请问在SAS中应该怎么编写这个程序?
比如有year id x,要y等于
year id x y
1999 1 2 .
2000 1 3 .
2001 1 4 (2+3+4)
2002 1 2 (3+4+2)
2003 1 2 (4+2+2)
1990 2 3 .
1991 2 4 .
1992 2 3 (3+4+3)
1993 2 3 (4+3+3)
1994 2 2 (3+3+2)
1995 2 4 (3+2+4)
1996 2 3 (2+4+3)
...

|
楼主: burnpark
|
4852
4
[原创博文] sas 累加 |
|
已卖:1份资源 讲师 21%
-
|
回帖推荐This is better and clear.
HTH
data a;
input year id x ;
cards;
1999 1 2
2000 1 3
2001 1 4
2002 1 2
2003 1 2
1990 2 3
1991 2 4
1992 2 3
1993 2 3
1994 2 2
1995 2 4
1996 2 3
;
data b;
set a;
by id year;
if first.id then m=0;
m+1;
x1=lag(x);
x2=lag2(x);
if m>=3 then y=sum(x, x1, x2);
else y=.;
drop m;
run;
proc print; run;
本帖被以下文库推荐
| ||
|
|
| ||
| ||
|
|
||
加好友,备注cda京ICP备16021002号-2 京B2-20170662号
京公网安备 11010802022788号
论坛法律顾问:王进律师
知识产权保护声明
免责及隐私声明


