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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1532 views
  • 1 like
  • 3 in conversation