<?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 Re: How to subtract a date from another date in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465229#M5593</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Patient_Name &amp;amp; $20.	Hire_Date :mmddyy10.	DOB :mmddyy10.;
format Hire_Date 	DOB mmddyy10.;
cards;
Gil Hart	12/23/2009	03/10/2008
Walker Shields	01/12/2003	07/29/1978
Sarah Shelton	04/10/2007	01/21/1942
;

data want;
set have;
 age=int(yrdif(dob,hire_date, 'AGE'));
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 25 May 2018 22:51:25 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-05-25T22:51:25Z</dc:date>
    <item>
      <title>How to subtract a date from another date</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465227#M5592</link>
      <description>&lt;P&gt;I am new to SAS and need to answer this question, but really don't know what to do. Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;I have DOB and Hire Date for each employee. I need to provide&amp;nbsp;SAS code to calculate the age at when they were hired?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if I should be using&amp;nbsp;intck('dtday', DOB, Hire_date)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is a sample dataset I am working with.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 22:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465227#M5592</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2018-05-25T22:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract a date from another date</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465229#M5593</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Patient_Name &amp;amp; $20.	Hire_Date :mmddyy10.	DOB :mmddyy10.;
format Hire_Date 	DOB mmddyy10.;
cards;
Gil Hart	12/23/2009	03/10/2008
Walker Shields	01/12/2003	07/29/1978
Sarah Shelton	04/10/2007	01/21/1942
;

data want;
set have;
 age=int(yrdif(dob,hire_date, 'AGE'));
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 May 2018 22:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465229#M5593</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-25T22:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract a date from another date</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465234#M5594</link>
      <description>&lt;P&gt;That did not work for me. When I plug that in, the new 'Age' cell is blank. And, it only shows the patients names that were typed into the code.&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 23:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465234#M5594</guid>
      <dc:creator>A_Halps</dc:creator>
      <dc:date>2018-05-25T23:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract a date from another date</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465235#M5595</link>
      <description>&lt;P&gt;are your dates, a numeric sas date variable/s. If yes that function is pretty straight forward and there isn't much I did besides knowing what the function does. So, i am hoping your sample that you posted is a good representative of your real and if that's the case it's mere sas function doing the job and no logic whatsoever from my part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So kindly check, verify ,and post us the correct sample, your log results and the output you got and your expected output please&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For further reading here is the link to the function&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1pmmr2dtec32an1vbsqmm3abil5.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1pmmr2dtec32an1vbsqmm3abil5.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please use the solution (2nd part) as test that on your real data. Forget the data have 1st part&lt;/P&gt;</description>
      <pubDate>Fri, 25 May 2018 23:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465235#M5595</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-25T23:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract a date from another date</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465239#M5596</link>
      <description>&lt;P&gt;Importing your data using Proc Import is reading dates as character values. If this is same for you then you need to convert them to Dates first and also your excel file column name are not valid when it comes to SAS. SAS will read as literal ( eg: 'Hire Date'n) This might cause issue downstream, so to avoid this you can use VALIDVARNAME=V7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your age you need to be careful about the Birth dates that fall on leap year. For precise age use the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS VALIDVARNAME=V7;
PROC IMPORT DATAFILE="E:\SASUniversityEdition\SandBox\Files\Q3_Dates.xlsx" 
	OUT=Q3_Dates
	DBMS=EXCEL
	REPLACE;
GETNAMES=YES;
QUIT;

DATA Q3_Dates_Age;
Format DOB_ HD mmddyy10.;
SET Q3_Dates;
DOB_DT=INPUT(strip(DOB),mmddyy10.);
Hire_DT=INPUT(Strip(Hire_Date),mmddyy10.);
age = FLOOR((intck("month", INPUT(strip(DOB),mmddyy10.),INPUT(Strip(Hire_Date),mmddyy10.))-
 (day(INPUT(Hire_Date,mmddyy10.)) &amp;lt; min(day(INPUT(DOB,mmddyy10.)), day(intnx ("month",INPUT(Hire_Date,mmddyy10.), 1)-1) )))/12); 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 May 2018 00:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-subtract-a-date-from-another-date/m-p/465239#M5596</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-26T00:56:47Z</dc:date>
    </item>
  </channel>
</rss>

