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 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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