SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
monday89
Fluorite | Level 6

I have the following dataset. What I would like to do is that set the final_stop_date_time to be the midnight of the start_date_time 

patientID start_date_time stop_date_time  
1 1/2/2019 1:40 1/2/2019 22:59  
2 2/3/2019 1:40    
3 4/4/2019 1:40 4/4/2019 23:59  

To this:

patientID start_date_time stop_date_time final_stop_date
1 1/2/2019 1:40 1/2/2019 22:59 1/2/2019 23:59
2 2/3/2019 1:40   2/3/2019 23:59
3 4/4/2019 1:40 4/4/2019 23:59 4/4/2019 23:59

 

i tried

intcx and intx but i couldn't get to set to midnight. any helpful would be great!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Something like this should work:

data want;
  set have;
  final_stop_date_time=intnx('dtday',stop_date_time,0,'e');
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Something like this should work:

data want;
  set have;
  final_stop_date_time=intnx('dtday',stop_date_time,0,'e');
run;

Art, CEO, AnalystFinder.com

 

monday89
Fluorite | Level 6

Thanks! It worked

ChrisNZ
Tourmaline | Level 20

> i tried intcx and intx but i couldn't get to set to midnight. any helpful would be great!

Just a terminology point: You don't really want midnight.

Midnight is generally considered 00:00 of the next day (or 12.00 am of the next day in the crazy am pm system), rather than 24:00 of the current day.

So @art297 's solution gives what you actually want and what you showed: the last moment of the current day.

 

Also note that there are ways to alter this convention in SAS, such as the DATATYPE=DATETIME_UTIL option for the picture format, which ends the day at 24:00.

 

 

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 2129 views
  • 1 like
  • 3 in conversation