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 |
|