There could be many approaches to this issue. What I am trying to do is compare all alarm1 and alarm2 for the same ptID and where the the alarm2 occurred within the prior 60 min (i.e 3600 seconds). Here is my code data test; informat Time anydtdtm15.; format Time datetime15.; input ptID Alarm1 Alarm2 Time; datalines; 01 0 1 02APR08:20:00 01 0 0 02APR08:22:15 01 1 0 02APR08:22:25 ;; run; data test1 (rename=(Time=time1)); set test( drop=alarm2); if alarm1; run; data test2(rename=(Time=time2) );; set test(drop=alarm1); if alarm2; run; proc sql; select a.ptid, a.alarm1, b.alarm2, (a.time1-b.time2) as difftime from test1 a cross join test2 b where a.ptid=b.ptid AND (a.time1-b.time2) ge 3600; quit; Please let me know if you have questions.
... View more