HI @bel2806 Assuming I understand your requirement
data have;
input Obs PtID deviceDt :date9. deviceTm :time5. alarm predictiveAlarm;
format deviceDt date9. deviceTm time5.;
cards;
1 1111 9-Sep-17 0:18 0 0
2 1111 9-Sep-17 0:28 0 0
3 1111 9-Sep-17 1:58 0 0
4 1111 9-Sep-17 2:08 0 1
5 1111 9-Sep-17 2:18 0 1
6 1111 9-Sep-17 2:28 0 1
7 1111 9-Sep-17 2:38 0 1
8 1111 9-Sep-17 2:48 0 0
9 1111 9-Sep-17 2:58 1 0
10 1111 9-Sep-17 3:08 1 0
11 1111 9-Sep-17 3:18 1 0
;
data want;
do _n_=-999 by 0 until(last.deviceDt);
set have;
by ptid deviceDt;
if predictiveAlarm then _t=deviceTm;
if not _a and alarm then do;
_a=deviceTm;
if 0<=intck('min',_t,_a)<=60 then _n_=_t;
end;
end;
do until(last.deviceDt);
set have;
by ptid deviceDt;
flag=deviceTm=_n_;
output;
end;
drop _:;
run;
proc print noobs;run;
Obs
PtID
deviceDt
deviceTm
alarm
predictiveAlarm
flag
1
1111
09SEP2017
0:18
0
0
0
2
1111
09SEP2017
0:28
0
0
0
3
1111
09SEP2017
1:58
0
0
0
4
1111
09SEP2017
2:08
0
1
0
5
1111
09SEP2017
2:18
0
1
0
6
1111
09SEP2017
2:28
0
1
0
7
1111
09SEP2017
2:38
0
1
1
8
1111
09SEP2017
2:48
0
0
0
9
1111
09SEP2017
2:58
1
0
0
10
1111
09SEP2017
3:08
1
0
0
11
1111
09SEP2017
3:18
1
0
0
... View more