k*******a 发帖数: 772 | 1 这种情况叫 last observation carry forward, 最好不要用lag改用retain
data aa;
retain lagid;
input id @3 vod mmddyy10. result $;
if id=. then id=lagid;
else lagid=id;
drop lagid;
datalines;
1 08/11/2000 normal
. 09/23/2001 normal
. 03/01/2002 abnormal
2 05/21/2000 normal
. 04/22/2001 normal
. 11/12/2001 normal
;
run; |
|
l****u 发帖数: 529 | 2 这个能简单一些?到现在我还没发现逻辑错误
proc sort data=yourdata;
by id date time;
run;
data yourdata;
set yourdata;
lagid=lag10(id);
lagtime=lag10(time);
lagdate=lag10(time);
if id=lagid and date=lagdate and time-lagtime<=60 then do;
indicator='robot';
output;
end;
run; |
|
l****u 发帖数: 529 | 3 又想了一下,作如下改动会更好
lagid=lag9(id);
lagtime=lag9(time);
lagdate=lag9(date); |
|