小鳄鱼a 发表于 2014-8-30 10:22
first.stkcd没有定义 传一份数据吧
data a;
set 你的数据;
where Dcost=.;
run;
proc sort data=a out=b;
by stkcd year;
run;
data c;
set b;
by stkcd year;
if first.stkcd then zong_quesheng=0;
zong_quesheng+1;
if last.stkcd;
run;
data d;
set b;
by stkcd year;
lag_year=lag(year);
if first.stkcd then lianxu_quesheng=1;
if year=lag_year+1 then lianxu_quesheng+1;
if last.stkcd;
run;
data final;
merge c d;
by stkcd year;
run;