Obsidian | Level 7

## Scanning observations with an hour of a flag variable

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
Tourmaline | Level 20

## Re: Scanning observations with an hour of a flag variable

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

Obsidian | Level 7

## Re: Scanning observations with an hour of a flag variable

Yes, flag observations by PtID and Date 🙂
Meteorite | Level 14

## Re: Scanning observations with an hour of a flag variable

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:0001      0           0      02APR08:22:1501      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 difftimefrom test1 a cross join test2 b where a.ptid=b.ptidAND  (a.time1-b.time2) ge 3600;quit;`

Please let me know if you have questions.

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