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!
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
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
Thanks! It worked
> 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.
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.