楼主: Lakeyi
2794 13

[有偿编程] 筛选需要的数值 [推广有奖]

11
Lakeyi 发表于 2014-8-1 11:27:50
freerunning_sky 发表于 2014-8-1 11:02
搞好了!有个问题就是 有的是从2006年开始的 有的是2001年  能不能都2001年开始

12
freerunning_sky 在职认证  发表于 2014-8-1 11:33:01
Lakeyi 发表于 2014-8-1 11:27
搞好了!有个问题就是 有的是从2006年开始的 有的是2001年  能不能都2001年开始
2001年的取什么值?还有最终都需要到2012年么?

13
freerunning_sky 在职认证  发表于 2014-8-1 11:33:37
Lakeyi 发表于 2014-8-1 11:25
报错咧=。=
我跑的很正常,不知道你怎么会报错

14
jiangpinggu 发表于 2014-8-1 14:28:55
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;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 09:48