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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.