Lakeyi 发表于 2014-8-1 09:41
大哥还能不能补充年份呢 没有的年份是默认上一年的
如要对缺失年份数据,用上一年数据进行补缺,则(你的文件名改为abcd,结果看test):
data tmp1;
set dmc2.abcd;
yr=year(shrchgdt);
run;
proc sort data = tmp1;
by stkcd shrchgdt;
run;
data tmp2;
set tmp1;
by stkcd yr;
if last.yr then output;
run;
data tmp3(keep= stkcd2 yr2 rename=(stkcd2=stkcd yr2=yr));
set tmp2;
by stkcd;
retain yr2 stkcd2;
if first.stkcd then do;yr2=yr;stkcd2=stkcd; output;end;
else if not(first.stkcd) and yr=yr2 then do;output;yr2=yr2+1;end;
else if not(first.stkcd) and yr>yr2 then do until (yr=yr2);
yr2=yr2+1;output;
end;
run;
data tmp4;
merge tmp3 tmp2;
by stkcd yr;
run;
data test(drop=a);
set tmp4;
by stkcd;
retain a;
if first.stkcd then a=NSHRTTL;
else if not(first.stkcd) and NSHRTTL ^=. then a=NSHRTTL;
else if not(first.stkcd) and NSHRTTL =. then NSHRTTL=a;
run;
proc datasets;
delete tmp1-tmp4;
run;