You should verify the output but I think this will get you the correct solution: data have; infile cards dsd; informat id1 id2 8. time datetime.; format id1 id2 8. time datetime.; input ID1 ID2 TIME; cards; 1234,12,22MAY2015:16:10:00.000 1234,12,22MAY2015:16:15:00.000 1234,12,12JUN2015:6:35:00.000 1234,12,12JUN2015:16:35:00.000 6549,45,15APR2015:16:10:00.000 6549,45,18APR2015:13:15:00.000 6549,45,18APR2015:13:18:00.000 6549,12,22MAY2015:14:15:00.000 6549,12,22MAY2015:14:20:00.000 ; run; proc sort data=have;by id1 id2 time; data want(drop=_:); set have; by id1 id2 time; format _l_time datetime.; _l_time = lag(time); if not first.id1 and not first.id2 then do; _diff_time = (time - _l_time)/60; end; if first.id2 or _diff_time > 10 then group + 1; run;
... View more