由买买提看人间百态

topics

全部话题 - 话题: previst
(共0页)
u*****b
发帖数: 14
1
来自主题: Statistics版 - SAS lag function question
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
来自主题: Statistics版 - SAS lag function question
data last2;
set aaa;
by id;
previst = lag(visit);
if first.id then previst=0;
run;
(共0页)