u*****b 发帖数: 14 | 1 the purpose is to get the previous visit number of a same id
the following lines give me an unexpected result. Anyone knows the reason?
thanks
data aaa;
input id $ visit;
cards;
10 1
10 2
10 4
2 1
2 2
;
run;
data last2;
set aaa;
if (id = lag(id)) then previst = lag(visit);
else previst=0;
run;
'last2' looks like this
id visit previst
10 1 0
10 2 .
10 4 2
2 1 0
2 2 4 |
o******6 发帖数: 538 | 2 data last2;
set aaa;
by id;
previst = lag(visit);
if first.id then previst=0;
run;
【在 u*****b 的大作中提到】 : the purpose is to get the previous visit number of a same id : the following lines give me an unexpected result. Anyone knows the reason? : thanks : data aaa; : input id $ visit; : cards; : 10 1 : 10 2 : 10 4 : 2 1
|
o******6 发帖数: 538 | 3 BTW,remember that the value returned by the lag function is the value of the
argument the last time the function was executed.
【在 u*****b 的大作中提到】 : the purpose is to get the previous visit number of a same id : the following lines give me an unexpected result. Anyone knows the reason? : thanks : data aaa; : input id $ visit; : cards; : 10 1 : 10 2 : 10 4 : 2 1
|
u*****b 发帖数: 14 | 4 o. i see. thanks
the
【在 o******6 的大作中提到】 : BTW,remember that the value returned by the lag function is the value of the : argument the last time the function was executed.
|
o******6 发帖数: 538 | 5 不客气,我也在学习中,以后多交流。
【在 u*****b 的大作中提到】 : o. i see. thanks : : the
|