<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Determine a Date based off of a Date variable and an Age variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874020#M345280</link>
    <description>&lt;P&gt;Hello SAS Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that includes patient's date of birth, patient's age at their inpatient screen and&amp;nbsp;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;Unfortunately, some of the dates did not calculate correctly. I've included my code and my output for your reference.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This was my output. Some dates calculated correctly, while others did not. It seems it has a challenge crossing over months and years?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ark123_0-1683240941854.png" style="width: 1029px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83638i0C109C9BDA0856BA/image-dimensions/1029x211?v=v2" width="1029" height="211" role="button" title="ark123_0-1683240941854.png" alt="ark123_0-1683240941854.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 22:56:01 GMT</pubDate>
    <dc:creator>ark123</dc:creator>
    <dc:date>2023-05-04T22:56:01Z</dc:date>
    <item>
      <title>Determine a Date based off of a Date variable and an Age variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874020#M345280</link>
      <description>&lt;P&gt;Hello SAS Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that includes patient's date of birth, patient's age at their inpatient screen and&amp;nbsp;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;Unfortunately, some of the dates did not calculate correctly. I've included my code and my output for your reference.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This was my output. Some dates calculated correctly, while others did not. It seems it has a challenge crossing over months and years?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ark123_0-1683240941854.png" style="width: 1029px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83638i0C109C9BDA0856BA/image-dimensions/1029x211?v=v2" width="1029" height="211" role="button" title="ark123_0-1683240941854.png" alt="ark123_0-1683240941854.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 22:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874020#M345280</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2023-05-04T22:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Determine a Date based off of a Date variable and an Age variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874022#M345281</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 May 2023 23:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874022#M345281</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-04T23:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Determine a Date based off of a Date variable and an Age variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874023#M345282</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;Inpat_months=input(scan(Age_at_Final_Inpatient_Screen,1), 8.);&lt;/LI-CODE&gt;&lt;LI-CODE lang="sas"&gt;Inpat_months=scan(Age_at_Final_Inpatient_Screen,1);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 23:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874023#M345282</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2023-05-04T23:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Determine a Date based off of a Date variable and an Age variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874153#M345350</link>
      <description>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.</description>
      <pubDate>Fri, 05 May 2023 14:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-a-Date-based-off-of-a-Date-variable-and-an-Age/m-p/874153#M345350</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-05T14:55:57Z</dc:date>
    </item>
  </channel>
</rss>

