yongyitian 发表于 2015-6-15 10:50 
多谢大神提点,我照葫芦画瓢:data have;
input group time people solution;
datalines;
1 0 0 0
1 3 1 1
1 5 2 3
1 6 3 4
1 7 4 6
1 10 5 7
1 11 6 8
1 21 7 9
1 27 8 12
2 4 0 0
2 6 5 3
2 7 6 5
2 8 7 7
2 12 8 8
2 17 10 9
2 24 12 13
; run;
proc sql noprint;
create table have_0 as
select distinct a.group, a.time, a.people, a.solution, max(b.people) as lag_people, max(b.solution) as lag_solution
from have a, have b
where a.time - b.time > 5 and a.group-b.group = 0
group by a.group, a.time;
quit;
data wanted;
merge have have_0;
by group time;
if missing(lag_people) then lag_people=0;
if missing(lag_solution) then lag_solution=0;
run;