【SAS NOTE】年累计
1 data a; 2 input date num; 3 datalines; 4 201201 1 5 201202 2 6 201203 3 7 201301 4 8 201302 5 9 ; 10 run; 11 data b; 12 set a; 13 c=substr(put(date,$6.),1,4); 14 run; 15 proc print data=b; 16 run; 17 data c; 18 set a; 19 retain; 20 y=substr(put(date,$6.),1,4); 21 m=substr(put(date,$6.),5,2); 22 if m='01' then 23 do 24 s=num; 25 y1=y; 26 m1=m; 27 end; 28 else 29 if y1=y then s=s+num; 30 run; 31 proc print data=c; 32 run;
最后把y m y1 m1等辅助变量drop