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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 3 replies
  • 920 views
  • 0 likes
  • 2 in conversation