Hi, how do I create a flag, WANT, that checks if 1AM falls between two timestamps?
data task1;
input ID :$2. BEG_DT_TIME :datetime18. END_DT_TIME :datetime18. WANT;
format BEG_DT_TIME END_DT_TIME datetime20.;
cards;
AA 28SEP2023:22:00:00.00 29SEP2023:02:00:00.00 1
BB 28SEP2023:07:30:00.00 28SEP2023:13:30:00.00 0
CC 28SEP2023:20:00:00.00 29SEP2023:00:00:00.00 0
DD 29SEP2023:00:00:00.00 29SEP2023:03:00:00.00 1
EE 29SEP2023:05:00:00.00 30SEP2023:03:00:00.00 1
;
run;
Use INTCK with a properly shaped interval:
data want;
set task1;
calc_want = intck('hour24.2',beg_dt_time,end_dt_time) > 0;
run;
Create an new timestamp using the datepart of end_dt_time to compare it with the start and end:
Want = (beg_dt_time <= dhms(datepart(end_dt_time), 1, 0, 0) <= end_dt_time);
Use INTCK with a properly shaped interval:
data want;
set task1;
calc_want = intck('hour24.2',beg_dt_time,end_dt_time) > 0;
run;
Thanks, @Kurt_Bremser . Curious what the .2 in hour24.2 does?
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.