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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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