我想写相同的子查询proc SQL到SAS代码帮助我

时间:2015-04-27 14:39:26

标签: sas proc

proc sql;
create table new as
select empid, name, salary, depno
from one
where  depno in(10,20) and 
salary<any
(select salary from one
where depno=30);
quit;

运行此代码后,我获得了depno(10,20)的工资,其工资低于depno 30的最高工资。所以我想要一个sas base中的相​​同程序,没有proc sql。有人可以帮我找到吗?

数据样本

empid name salary depno
    7369:SMITH:800.00:20
    7499:ALLEN:1600.00:30
    7521:WARD:1250.00:30
    7566:JONES:2975.00:20
    7654:MARTIN:1250.00:30
    7698:BLAKE:2850.00:30
    7782:CLARK:2450.00:10
    7788:SCOTT:3000.00:20
    7839:KING:5000.00:10
    7844:TURNER::1500.00:30
    7876:ADAMS:1100.00:20
    7900:JAMES::950.00:30
    7902:FORD:3000.00:20
    7934:MILLER:1300.00:10
    7369:SMITH:80s.00:20

1 个答案:

答案 0 :(得分:-1)

您可以通过两个数据步骤完成此操作。请尝试以下方法:

第一个数据步骤为depno(30)提取最大工资并将其置于宏变量&amp; max30;

第二个数据步骤会提取您感兴趣的记录。

data _null_;
set one;
retain max30;
if (_n_ = 1) then max30 = -999999999;
if (depno = 30 and salary > max30) then max30 = salary;
call symput("max30",max30);
end;

data new;
set one;
if ( (depno = 10 or depno = 20) and salary < &max30) then output;
run;