BookmarkSubscribeRSS Feed
Abishekaa
Obsidian | Level 7

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

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

And do what? Flag all observations for piID = '01'?

Abishekaa
Obsidian | Level 7
Yes, flag observations by PtID and Date 🙂
Sajid01
Meteorite | Level 14

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 591 views
  • 0 likes
  • 3 in conversation