<?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: Age Calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475965#M122443</link>
    <description>You can't use a function in proc sql.</description>
    <pubDate>Fri, 06 Jul 2018 12:09:18 GMT</pubDate>
    <dc:creator>tomrvincent</dc:creator>
    <dc:date>2018-07-06T12:09:18Z</dc:date>
    <item>
      <title>Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475777#M122366</link>
      <description>&lt;P&gt;I've seen some discussions of age calculation (especially when 2/28, 2/29 and 3/1 are involved)...here's my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro age (bday, eday);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;INTCK('YR', &amp;amp;bday, &amp;amp;eday)-((put(&amp;amp;eday,mmddyyb4.)&amp;lt;(put(&amp;amp;bday,mmddyyb4.))))&lt;/P&gt;
&lt;P&gt;%mend age;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can then be called:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;select *,%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT) as age from xdata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-or-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; xxx; set xdata; age=%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT); &lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475777#M122366</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-05T18:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475778#M122367</link>
      <description>&lt;P&gt;I think the best bet for age and the most robust is using&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;YRDIF Function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;\&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;handles leap years too&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475778#M122367</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-05T18:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475788#M122368</link>
      <description>&lt;P&gt;I wish it did, but it doesn't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;birthday of&amp;nbsp;02/29/1960, date of&amp;nbsp;02/27/1965: yrdif gives&amp;nbsp;4.997260274, which is wrong. Should be 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;birthday of&amp;nbsp;02/29/1960, date of&amp;nbsp;02/28/1965: yrdif gives 5, which is wrong.&amp;nbsp; Should also be 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's why I came up with the macro.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 19:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475788#M122368</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-05T19:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475794#M122369</link>
      <description>&lt;P&gt;Ok, looks like you are looking for actuals with an int&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data w;&lt;BR /&gt;age=int(yrdif('29feb1960'd, '27feb1965'd, 'ACT/ACT'));&lt;BR /&gt;age1=int(('27feb1965'd-'29feb1960'd)/365.25);&lt;BR /&gt;age2=int(yrdif('29feb1960'd, '28feb1965'd, 'ACT/ACT'));&lt;BR /&gt;age3=int(('28feb1965'd-'29feb1960'd)/365.25);&lt;BR /&gt;put _all_;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 19:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475794#M122369</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-05T19:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475799#M122370</link>
      <description>&lt;P&gt;Any reason to not create a function instead of a macro here?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144199"&gt;@tomrvincent&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've seen some discussions of age calculation (especially when 2/28, 2/29 and 3/1 are involved)...here's my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro age (bday, eday);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;INTCK('YR', &amp;amp;bday, &amp;amp;eday)-((put(&amp;amp;eday,mmddyyb4.)&amp;lt;(put(&amp;amp;bday,mmddyyb4.))))&lt;/P&gt;
&lt;P&gt;%mend age;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can then be called:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;select *,%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT) as age from xdata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-or-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; xxx; set xdata; age=%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT); &lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 20:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475799#M122370</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-05T20:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475801#M122371</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age=intck('Year', '29feb1960'd, '27feb1965'd, 'C');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144199"&gt;@tomrvincent&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I've seen some discussions of age calculation (especially when 2/28, 2/29 and 3/1 are involved)...here's my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro age (bday, eday);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;INTCK('YR', &amp;amp;bday, &amp;amp;eday)-((put(&amp;amp;eday,mmddyyb4.)&amp;lt;(put(&amp;amp;bday,mmddyyb4.))))&lt;/P&gt;
&lt;P&gt;%mend age;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can then be called:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;select *,%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT) as age from xdata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-or-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; xxx; set xdata; age=%&lt;STRONG&gt;&lt;EM&gt;age&lt;/EM&gt;&lt;/STRONG&gt;(BIRTH_DT, CLAIM_RECD_DT); &lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 20:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475801#M122371</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-05T20:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475963#M122441</link>
      <description>&lt;P&gt;yeah..I've looked at that...it doesn't work either.&amp;nbsp; Birthday of 29FEB1952 and event day of 28FEB2017 should be 64, not 65.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't just arbitrarily come up with that macro...I compared various combinations of yrdif, intck and so on but they don't correctly handle the 29/28 case.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475963#M122441</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-06T11:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475965#M122443</link>
      <description>You can't use a function in proc sql.</description>
      <pubDate>Fri, 06 Jul 2018 12:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475965#M122443</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-06T12:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475970#M122447</link>
      <description>That works as well!  I will present that to management as an alternative. Thanks!</description>
      <pubDate>Fri, 06 Jul 2018 12:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/475970#M122447</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-06T12:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/476009#M122460</link>
      <description>but age4=int(yrdif('29Mar1960'd, '29Mar1965'd, 'ACT/ACT')); gives 4 instead of 5.</description>
      <pubDate>Fri, 06 Jul 2018 13:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/476009#M122460</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-07-06T13:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Age Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/476095#M122485</link>
      <description>&lt;P&gt;A precise macro was created years ago by Billy Kreuter.&amp;nbsp; See&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.pauldickman.com/teaching/sas/age.php" target="_blank"&gt;http://www.pauldickman.com/teaching/sas/age.php&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/publishing/authors/extras/61860_update.pdf" target="_blank"&gt;http://support.sas.com/publishing/authors/extras/61860_update.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 17:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Age-Calculation/m-p/476095#M122485</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2018-07-06T17:59:30Z</dc:date>
    </item>
  </channel>
</rss>

