Hello SAS Community,
I have a dataset that includes patient's date of birth, patient's age at their inpatient screen and patient's age at their outpatient screen. I need to determine the time between the patient's inpatient screen and outpatient screen in the number of days. The challenge is that the age at both the inpatient and outpatient screens are provided in a # months, # days format.
I first pulled out just the number of months (without the word months) and just the number of days (without the word days) as new variables for both screens. I then tried to calculate the date of each screen based off the patient's birth date and their age using the newly created months and days variables. Lastly, I used the datedif function to calculate the time between these two dates. Unfortunately, some of the dates did not calculate correctly. I've included my code and my output for your reference.
data test;
set sample;
Inpat_months=scan(Age_at_Final_Inpatient_Screen,1);
Inpat_days=scan(Age_at_Final_Inpatient_Screen,3);
Outpat_months=scan(Age_at_Final_Outpatient_Screen,1);
Outpat_days=scan(Age_at_Final_Outpatient_Screen,3);
run;
data test2;
set test;
InptDate1 = intnx("MONTHS", Patient_Date_of_Birth, Inpat_months);
format InptDate1 MMDDYY10.;
OutptDate1 = intnx("MONTHS", Patient_Date_of_Birth, Outpat_months);
format OutptDate1 MMDDYY10.;
run;
data test2;
set test2;
Date_InptScrn = intnx("DAYS", InptDate1, Inpat_days);
format Date_InptScrn MMDDYY10.;
Date_OutptScrn = intnx("DAYS", OutptDate1, Outpat_days);
format Date_OutptScrn MMDDYY10.;
run;
data test3;
set test2;
Time_to_OutptScrn = datdif(Date_InptScrn, Date_OutptScrn, 'act/act');
run;
This was my output. Some dates calculated correctly, while others did not. It seems it has a challenge crossing over months and years?
Thanks for your reply. I removed the input and 8. addition to the first section of the code you shared (see below) and it worked. It seems the 's' alignment was what was missing.
Inpat_months=input(scan(Age_at_Final_Inpatient_Screen,1), 8.);
Inpat_months=scan(Age_at_Final_Inpatient_Screen,1);
Thanks for your help!
I think you're on the right path, but want to use the 's' alignment for INTNX(). You only have two records with both inpatient and outpatient dates, and both are the same issue so hard to tell exactly.
data test;
set sample;
Inpat_months=input(scan(Age_at_Final_Inpatient_Screen,1), 8.);
Inpat_days=input(scan(Age_at_Final_Inpatient_Screen,3), 8.);
Outpat_months=input(scan(Age_at_Final_Outpatient_Screen,1), 8.);
Outpat_days=input(scan(Age_at_Final_Outpatient_Screen,3), 8.);
*increment months;
InptDate1 = intnx("MONTHS", Patient_Date_of_Birth, Inpat_months, 's');
OutptDate1 = intnx("MONTHS", Patient_Date_of_Birth, Outpat_months, 's');
format InptDate1 OutptDate1 MMDDYY10.;
Date_InptScrn = intnx("DAYS", InptDate1, Inpat_days);
Date_OutptScrn = intnx("DAYS", OutptDate1, Outpat_days);
format Date_InptScrn Date_OutptScrn MMDDYY10.;
time_to_outptscrn = date_outptScrn - date_InptScrn;
run;
Thanks for your reply. I removed the input and 8. addition to the first section of the code you shared (see below) and it worked. It seems the 's' alignment was what was missing.
Inpat_months=input(scan(Age_at_Final_Inpatient_Screen,1), 8.);
Inpat_months=scan(Age_at_Final_Inpatient_Screen,1);
Thanks for your help!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.