BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

Hello. I have the following dataset per subject ID where i need to calculate difference in hours based on each day. Logic:

  • For day = 0, where i need to take the MAX DRUG_stop_DTM - Enrolled_DTM.
  • Next days (EXCEPT THE LAST DAY for that subjectID), the difference in hours needs to be static set to 24 hours. 
  • Last day: final_stop_DTM - first drug_start_dtm for that last day. If the "Final_stop_dtm" is missing then use max drug_stop_dtm for that day 

 

Have:

PatientID Enrolled_DTM days Drug_start_DTM Drug_stop_STM WEIGHT final_stop_DTM
1232 26MAR2020:13:30:00 0 26MAR20:13:30:00 26MAR20:23:59:59 74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 1 27MAR20:00:00:00 27MAR20:23:59:59 74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 1 27MAR20:03:46:00   74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 1 27MAR20:20:04:00   74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 2 28MAR20:00:00:00 28MAR20:13:00:00 74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 2 28MAR20:04:11:00   74.2 28MAR2020:21:56:00
1232 26MAR2020:13:30:00 2 28MAR20:04:46:00   74.2 28MAR2020:21:56:00
4456 02JAN2020:16:11:00 0 02JAN20:18:16:00 02JAN20:23:59:59 80.9 .
4456 02JAN2020:16:11:00 1 03JAN20:00:00:00 03JAN20:15:50:00 80.9 .
4456 02JAN2020:16:11:00 1 03JAN20:15:50:00 03JAN20:23:59:59 80.9 .
4456 02JAN2020:16:11:00 2 04JAN20:00:00:00 04JAN20:21:11:00 80.9 .

 

want;

PatientID days WEIGHT hours_difference
1232 0 74.2 10.5
1232 1 74.2 24
1232 2 74.2 22
4456 0 80.9 7.82
4456 1 80.9 24
4456 2 80.9 21.18

 

What I have done so far is break the dataset by days. for day = 0 but then i wasn't sure how to do the "last" by group per patient

 

any help is appreciated. 

 

1 REPLY 1
LeonidBatkhan
Lapis Lazuli | Level 10

Hi monday89,

Here is how you can set up you logic:

proc sort data=A out=B; 
   by PatientID Days;
run;

data C;
   set B;
   by PatientID Days;
   if first.Days then
   do;
      /* do your first observation (Days=0) processing */
   end;
   else
   if last.Days then
   do;
      /* do your last day processing */
   end;
   else
   do;
      /* do your processing for other days except last */
   end;
run;

Hope this helps.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1 reply
  • 269 views
  • 0 likes
  • 2 in conversation