Hi,
I have a dataset similar to the one below. For all cases where there is an Alarm1, I want to find out if an Alarm2 occurred within 60 minutes PRIOR to the Alarm1. Hope this makes sense 🙂 I have tried using intck and intnx functions, but they always return one record. I can't find a way to scan all records that are 60 minutes PRIOR, when Alarm1 =1. Any ideas on how to make it work? Thanks so much!
ptID Alarm1 Alarm2 Time
01 0 1 02APR08: 22:10
01 0 0 02APR08: 22:15
01 1 0 02APR08: 22:25
And do what? Flag all observations for piID = '01'?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: