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

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?

ark123_0-1683240941854.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ark123
Obsidian | Level 7

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!

View solution in original post

3 REPLIES 3
Reeza
Super User

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;

ark123
Obsidian | Level 7

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!

Reeza
Super User
You should have notes in your log about implicit type conversion then, where the character values are being converted to numeric. The input converts the character values to numeric to avoid those notes in the log.

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
  • 3 replies
  • 361 views
  • 1 like
  • 2 in conversation