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.
SubjectID | start_date_time | stop_date_time | formGroup |
1 | 21NOV19:18:04:00 | 22NOV19:17:30:00 | Day 1 |
1 | 22NOV19:17:30:00 | 23NOV19:14:46:00 | Day 2 |
2 | 11NOV19:04:22:00 | 11NOV19:05:00:00 | Day 1 |
2 | 11NOV19:05:00:00 | 12NOV19:01:00:00 | Day 1 |
2 | 12NOV19:01:00:00 | 12NOV19:08:25:00 | Day 2 |
New dataset:
SubjectID | start_date_time | stop_date_time | formGroup | New_stop_date |
1 | 21NOV19:18:04:00 | 22NOV19:17:30:00 | Day 1 | 21NOV19:23:59:59 |
1 | 22NOV19:17:30:00 | 23NOV19:14:46:00 | Day 2 | 22NOV19:23:59:59 |
2 | 11NOV19:04:22:00 | 11NOV19:05:00:00 | Day 1 | 11NOV19:05:00:00 |
2 | 11NOV19:05:00:00 | 12NOV19:01:00:00 | Day 1 | 11NOV19:23:59:59 |
2 | 12NOV19:01:00:00 | 12NOV19:08:25:00 | Day 2 | 12NOV19:08:25:00 |
Why is the fourth row of the output data set have new_stop_date 12NOV19:23:59:59 and not 11NOV19:23:59:59 ??
Good catch. I'll fix it!
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...
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: