程序
data a;
input a;
cards;
1
1
1
2
2
2
2
4
4
4
;
run;
data a;
set a;
if a=lag(a) then p=a*lag(a);
run;
希望的输出结果应该为:即每个组(a)第一个观察没有对应的p
1 .
1 1
1 1
2 .
2 2
2 4
2 4
4 .
4 8
4 16
实际的结果为:第二行也没有对也的p,为什么?
1
1
1 1
2
2 2
2 4
2 4
4
4 8
4 16

|
楼主: 3fatty
|
3996
3
[求助]关于lag的问题 |
|
已卖:2091份资源 硕士生 17%
-
|
回帖推荐"lag函数是不能在条件语句一同使用的,否则会出错"
Put in this way, lag is executable statement and implemented in stack. When it gets executed, then pop-and-push. So the result may not be as one's expectation.
See example (no error)
data t1;
do i=1,2,3,3 ;
x=ranuni(10);
output;
end;
run;
data t2;
set t1;
y=lag(i);
if i in (1,3) then z=lag(x);
run;
...
本帖被以下文库推荐
| ||
|
|
| ||
加好友,备注cda京ICP备16021002号-2 京B2-20170662号
京公网安备 11010802022788号
论坛法律顾问:王进律师
知识产权保护声明
免责及隐私声明


