BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dataMart87
Quartz | Level 8

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;
1 ACCEPTED SOLUTION
4 REPLIES 4
andreas_lds
Jade | Level 19

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);
dataMart87
Quartz | Level 8

Thanks, @Kurt_Bremser .  Curious what the .2 in hour24.2 does?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 4 replies
  • 1023 views
  • 4 likes
  • 3 in conversation