BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stancemcgraw
Obsidian | Level 7

Hello,

   Im trying to generate the difference between the first and last dates that a patient was on a certain medication in hours. These are listed in the same column.

 

Data have:

studynum    med_admin_date

1                    10/26/20 8:00

1                     10/27/20 3:00

1                     10/28/20 8:00

 

data want:

studynum     difference

1                     48

1 ACCEPTED SOLUTION
2 REPLIES 2
PaigeMiller
Diamond | Level 26

Are these valid numeric SAS date/time values? What is the type of variable MED_ADMIN_DATE (numeric or character) according to PROC CONTENTS? What is the format of variable MED_ADMIN_DATE according to PROC CONTENTS?

 

If they are valid numeric SAS datetime value, then PROC SUMMARY gets the job done, it finds the difference in seconds, and then you can divide by 3600 to get hours.

 

proc summary data=have;
     class studynum;
     var MED_ADMIN_DATE;
     output out=want range=/autoname;
run;

data want; 
    set want;
    hours=MED_ADMIN_DATE_range/3600;
run;
--
Paige Miller

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 2 replies
  • 1372 views
  • 0 likes
  • 3 in conversation