BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

HI. I have the following table below. If the subject has start DATE is different or at a later date of stop date, I would like to cut the stop date to END at before midnight before the next day. If not, keep the same stop date. I have no idea how to start. I tried to break the start date and time as only date and then see if it start date= stop date, then keep stop date. If not then use midnight of that date. but it was pretty long. 

 

 

SubjectIDstart_date_timestop_date_timeformGroup
121NOV19:18:04:0022NOV19:17:30:00Day 1
122NOV19:17:30:0023NOV19:14:46:00Day 2
211NOV19:04:22:0011NOV19:05:00:00Day 1
211NOV19:05:00:0012NOV19:01:00:00Day 1
212NOV19:01:00:0012NOV19:08:25:00Day 2

 

 

New dataset:
 

SubjectIDstart_date_timestop_date_timeformGroupNew_stop_date
121NOV19:18:04:0022NOV19:17:30:00Day 121NOV19:23:59:59
122NOV19:17:30:0023NOV19:14:46:00Day 222NOV19:23:59:59
211NOV19:04:22:0011NOV19:05:00:00Day 111NOV19:05:00:00
211NOV19:05:00:0012NOV19:01:00:00Day 111NOV19:23:59:59
212NOV19:01:00:0012NOV19:08:25:00Day 212NOV19:08:25:00
3 REPLIES 3
PaigeMiller
Diamond | Level 26

Why is the fourth row of the output data set have new_stop_date 12NOV19:23:59:59 and not 11NOV19:23:59:59 ??

 

--
Paige Miller
monday89
Fluorite | Level 6

Good catch. I'll fix it!

PaigeMiller
Diamond | Level 26
data want;
    set have;
    if datepart(stop_date_time)>datepart(start_date_time) then 
        new_stop_date=hdms(datepart(start_date_time),23,59,59);
    else new_stop_date=stop_date_time;
run; 

Suggestion: spend some time reading the SAS documentation regarding date and datetime and time functions. https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=allprodslang&docsetTarget=syn...

--
Paige Miller

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 16. 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
  • 419 views
  • 0 likes
  • 2 in conversation