<?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: Calculate Age from Birth Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434998#M108010</link>
    <description>&lt;P&gt;is it a datetime value rather than a date value then use:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age=floor(YRDIF(datepart(birth_Date), today(),"AGE"))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 18:46:53 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-02-07T18:46:53Z</dc:date>
    <item>
      <title>Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434973#M107998</link>
      <description>&lt;P&gt;I've seen some other threads about this but haven't been able to get my code to work based on those.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The date variable (BIRTH_DATE) in my dataset is formatted as DDMMMYYYY and I've trying to create an age integer variable from it like '21'. Below is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE age_pool AS SELECT * FROM test
ORDER BY ID;
QUIT;

DATA age_calc; SET age_pool;
today=DATE();
age = FLOOR((INTCK('month',BIRTH_DATE,today) - (day(today) &amp;lt; day(BIRTH_DATE)))/12);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This gives me the variable 'today' filled out properly but the age column is blank.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434973#M107998</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434976#M107999</link>
      <description>&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;age=floor(YRDIF(birth_Date, today(),"AGE"))&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434976#M107999</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-07T18:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434978#M108000</link>
      <description>Today is missing the parenthesis, so SAS thinks it's a variable not a function that returns the value of todays date. Try TODAY().</description>
      <pubDate>Wed, 07 Feb 2018 18:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434978#M108000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-07T18:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434981#M108001</link>
      <description>&lt;P&gt;While there are many formulas for age, let me just comment on your code, not on any one formula or another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have unbalanced parentheses.&amp;nbsp; The missing closing parenthesis would go &lt;FONT color="#ff0000"&gt;here&lt;/FONT&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;(day&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;today&lt;FONT color="#ff0000"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;day&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;BIRTH_DATE&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434981#M108001</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T18:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434985#M108002</link>
      <description>&lt;P&gt;Yes sorry, I accidentally deleted it when I copied it over and had to rename one of the variables for privacy. I correct the parentheses, this does not resolve the issue when I run the code.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434985#M108002</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434987#M108003</link>
      <description>Still get a blank output for age. Do I need to reformat the BIRTH_DATE variable?</description>
      <pubDate>Wed, 07 Feb 2018 18:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434987#M108003</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434988#M108004</link>
      <description>&lt;P&gt;OK, given that correction, the next issue is the contents of BIRTH_DATE.&amp;nbsp; Is it actually a SAS date, or is it a character string in DDMMMYYYY form?&amp;nbsp; PROC CONTENTS will tell you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's a character string, the DATA step references (not the SQL code) to BIRTH_DATE should be replaced by:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input(birth_date, date9.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, messages from your SAS log might be helpful here.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434988#M108004</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T18:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434989#M108005</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189906"&gt;@spcoman&lt;/a&gt; wrote:&lt;BR /&gt;Still get a blank output for age. Do I need to reformat the BIRTH_DATE variable?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post your code and log.&lt;/P&gt;
&lt;P&gt;And include the format and type for the variable birth_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434989#M108005</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-07T18:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434997#M108009</link>
      <description>That variable is&lt;BR /&gt;&lt;BR /&gt;Type: Numeric&lt;BR /&gt;Group: Date&lt;BR /&gt;Informat: DATETIME20.</description>
      <pubDate>Wed, 07 Feb 2018 18:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434997#M108009</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434998#M108010</link>
      <description>&lt;P&gt;is it a datetime value rather than a date value then use:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age=floor(YRDIF(datepart(birth_Date), today(),"AGE"))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434998#M108010</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-07T18:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434999#M108011</link>
      <description>When I run that code I get the following error,&lt;BR /&gt;&lt;BR /&gt;"WARNING: Limit set by ERRORS= option reached..."</description>
      <pubDate>Wed, 07 Feb 2018 18:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/434999#M108011</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435001#M108012</link>
      <description>That worked. Just so I understand, the issue is that it was a datetime format instead of a date format?&lt;BR /&gt;&lt;BR /&gt;Does that solution account for leap years in the age calc?</description>
      <pubDate>Wed, 07 Feb 2018 18:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435001#M108012</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435004#M108013</link>
      <description>&lt;P&gt;Yes, yrdif accounts for leap years! It takes the approach that one born on Feb 29 of a leap year ages another year on Feb 28 of a non-leap year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 18:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435004#M108013</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-07T18:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435007#M108016</link>
      <description>Thank you!</description>
      <pubDate>Wed, 07 Feb 2018 18:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/435007#M108016</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-07T18:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Age from Birth Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/445573#M111678</link>
      <description>&lt;P&gt;I used the INTCK method for years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;AGE=INT((INTCK('MONTH',DOB,refDate) - (DAY(refDate)&amp;lt;DAY(DOB)))/12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I stopped using it when I discovered that the calculation would sometimes produce odd results. Especially when trying to find newborns where age is less than 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use the YRDIF method&amp;nbsp; now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; AGE = INT(yrdif(DOB,refDate,'actual'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Working with dates is always tricky and you should always check your results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With some recent data, I was using the YRDIF method and ran into some special cases where I was calculating ages on some claims data for children across three different years. The precision of the MemberDateOfBirth (a stored SAS date variable) was causing the age15 variable to resolve to 18 with no decimal places for children born 31Dec1996 using 31Dec2015 as the reference year. The reference to the variable "age15b" below was because when I tested the YRDIF method for age15 below without the INT function, the age resolved to 19.000.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This only occurred for the children born 31Dec1996 using 31Dec2015 as a reference date. The same issue didn't happen to any other Dec 31st children for any of the other years in my data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yearDOB = year(MemberDateOfBirth);&lt;/P&gt;
&lt;P&gt;age15 = INT(yrdif(MemberDateOfBirth,'31Dec2015'd,'actual'));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;** fix special case where only for reference year 2015, kids born on&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Dec 31 are getting odd ages of 19.000 for age15 and 18 for age15b.&lt;BR /&gt;&amp;nbsp; &amp;nbsp;This only affects 2015 reference year.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if age15 eq 18 and MemberDateOfBirth eq '31DEC1996'd then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;age15 = 19;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 18:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Age-from-Birth-Date/m-p/445573#M111678</guid>
      <dc:creator>Stephen</dc:creator>
      <dc:date>2018-03-14T18:25:19Z</dc:date>
    </item>
  </channel>
</rss>

