I need to create a flag defining whether an incident has started within the first 24 hours of the sdate.
something like below
any help on how to do it
sdate incident flag
04DEC2018 05DEC2018 Y
08JAN2018 03JAN2018 N
With datetimes:
data have;
input sdate :e8601dt19. incident :e8601dt19.;
format sdate incident e8601dt19.;
cards;
2018-12-04T10:03 2018-12-05T09:03
2018-01-08T13:03 2018-01-03T10:03
;
run;
data want;
set have;
flag = ifc(0 <= intck('dtday',sdate,incident,'c') <= 1,'Y','N');
run;
proc print data=want noobs;
run;
Result:
sdate incident flag 2018-12-04T10:03:00 2018-12-05T09:03:00 Y 2018-01-08T13:03:00 2018-01-03T10:03:00 N
Are you working with date or datetime values?
i have both date and datetime variables, datetime is character variable something like "2018-12-05T12:00" .
datetime makes sense to calculate flag if i am not wrong.
Like this?
FLAG = ifc(-1 <= SDATE-INCIDENT <= 1, 'Y', 'N');
sorry if it is datetime like below than how to do?
sdate incident flag
04DEC2018T10:03 05DEC2018T09:03 Y
08JAN2018T13:03 03JAN2018T10:03 N
If you don't consider the time:
FLAG = ifc(-1 <= (input(SDATE,date9.) - input(INCIDENT,date9.)) <= 1, 'Y', 'N');
i want to consider time, can i do something like this?
FLAG = ifc(-1 <= (SDATE- INCIDENT) <= 1, 'Y', 'N');
With datetimes:
data have;
input sdate :e8601dt19. incident :e8601dt19.;
format sdate incident e8601dt19.;
cards;
2018-12-04T10:03 2018-12-05T09:03
2018-01-08T13:03 2018-01-03T10:03
;
run;
data want;
set have;
flag = ifc(0 <= intck('dtday',sdate,incident,'c') <= 1,'Y','N');
run;
proc print data=want noobs;
run;
Result:
sdate incident flag 2018-12-04T10:03:00 2018-12-05T09:03:00 Y 2018-01-08T13:03:00 2018-01-03T10:03:00 N
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.