sas实例合集

输出数据集的最后一条观测值

*使用nobs+point选项,这个更划算,第二个必须把整个数据集全部读入;
data b;
set sashelp.class nobs=last point=last; output; stop; run;
*使用end选项; data a;
set sashelp.class end=last; if last then output; run;

 输出by组的第一条或最后一条观测值到新的数据集

*获得最后一条用last,也可以在排序的时候就用降序排序;
data a; input x y @@; cards;
1 20 1 10 1 30 2 40 2 50 ; run; /*proc sort data=b nodupkey out=c;by x;run;*/ proc sort data=a out=b;by x y;run; data b_if; set b; by x; if first.x then output; run;
/*效率高于and?我觉得这个效率一样*/
if
status1 = 1 then if status2 = 5 then if status4 = 9 then output;
if status1=1 and status2=5 and status4=9 then output;
/*效率高于or,or需要判断所有的*/
if status in (1 2 3) then x=1; if status=1 or status=2 or status=3 then x=1;
原文地址:https://www.cnblogs.com/yican/p/3813697.html