<?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: Calculating Age in SAS by assigning cases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352392#M82131</link>
    <description>&lt;P&gt;Use COALESCE instead, but I suspect your error is related to missing parentheses and incorrect SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;int(yrdif(dt_birth,date(),'ACT/365') -&amp;gt; You have 3 open and only 2 closing parentheses.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;END - no variable name here?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;int(yrdif(dt_birth, coalesce(dt_death, date()), 'ACT/365') as Age&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a CASE statement it would be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
   when not missing(dt_death) then int(yrdif(dt_birth, dt_death, 'ACT/365'))
   else int(yrdif(dt_birth, date(), 'ACT/365'))
end as AGE&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Apr 2017 03:58:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-04-22T03:58:46Z</dc:date>
    <item>
      <title>Calculating Age in SAS by assigning cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352388#M82128</link>
      <description>&lt;P&gt;Hi. This is my data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dt_birth &amp;nbsp;dt_death&amp;nbsp;&lt;/P&gt;&lt;P&gt;4/21/1957 4/21/1967&lt;/P&gt;&lt;P&gt;4/21/1965&amp;nbsp;&lt;/P&gt;&lt;P&gt;4/3/1976&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to create a 3rd column called age. It should be dt_death - dt_birth if dt_death is present or otherwise it&amp;nbsp;should be today's date- dt_death.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the following procedure but it is giving syntax errors&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql&amp;nbsp;;&lt;/P&gt;&lt;P&gt;create table new as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select *, case Age&amp;nbsp;&lt;/P&gt;&lt;P&gt;when dt_death is not null then int(yrdif(dt_birth,dt_death,'ACT/365')&lt;/P&gt;&lt;P&gt;else&amp;nbsp;&lt;SPAN&gt;int(yrdif(dt_birth,date(),'ACT/365')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;end&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;from old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I think there is a problem here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when dt_death is not null then &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;can you suggest any alternative methods?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 03:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352388#M82128</guid>
      <dc:creator>swar</dc:creator>
      <dc:date>2017-04-22T03:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Age in SAS by assigning cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352392#M82131</link>
      <description>&lt;P&gt;Use COALESCE instead, but I suspect your error is related to missing parentheses and incorrect SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;int(yrdif(dt_birth,date(),'ACT/365') -&amp;gt; You have 3 open and only 2 closing parentheses.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;END - no variable name here?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;int(yrdif(dt_birth, coalesce(dt_death, date()), 'ACT/365') as Age&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a CASE statement it would be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
   when not missing(dt_death) then int(yrdif(dt_birth, dt_death, 'ACT/365'))
   else int(yrdif(dt_birth, date(), 'ACT/365'))
end as AGE&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Apr 2017 03:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352392#M82131</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-22T03:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Age in SAS by assigning cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352394#M82132</link>
      <description>Thanks a lot Reeza!! It worked!!</description>
      <pubDate>Sat, 22 Apr 2017 04:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Age-in-SAS-by-assigning-cases/m-p/352394#M82132</guid>
      <dc:creator>swar</dc:creator>
      <dc:date>2017-04-22T04:03:38Z</dc:date>
    </item>
  </channel>
</rss>

