<?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 How can i calculate  age by &amp;quot;yrdif&amp;quot; in macro function ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708034#M217496</link>
    <description>&lt;P&gt;&amp;nbsp;I created a macro function to calculated&amp;nbsp; age between two date and filtered data with specific time interval. However, i didn't understand why the following function output with 'age' as&amp;nbsp; '.' just like the below figure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let a = 10;&lt;BR /&gt;%macro filter_age(age_start, age_end);&lt;BR /&gt;&lt;BR /&gt;%local today_;&lt;BR /&gt;%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0), date9.);&lt;/P&gt;&lt;P&gt;proc sql outobs = &amp;amp;a;&lt;BR /&gt;create table filter_age as&lt;BR /&gt;select distinct cif_num, yrdif(birth_dt, "&amp;amp;today_"d, 'actual') as age&lt;BR /&gt;from test&lt;/P&gt;&lt;P&gt;where calcuated age between &amp;amp;age_start and &amp;amp;age_end&lt;BR /&gt;quit;&lt;BR /&gt;%mend filter_age;&lt;BR /&gt;%filter_age(10, 20);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EvansHsieh_0-1608782613234.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52999iA5366860B797DEB0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EvansHsieh_0-1608782613234.png" alt="EvansHsieh_0-1608782613234.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Dec 2020 04:03:42 GMT</pubDate>
    <dc:creator>EvansHsieh</dc:creator>
    <dc:date>2020-12-24T04:03:42Z</dc:date>
    <item>
      <title>How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708034#M217496</link>
      <description>&lt;P&gt;&amp;nbsp;I created a macro function to calculated&amp;nbsp; age between two date and filtered data with specific time interval. However, i didn't understand why the following function output with 'age' as&amp;nbsp; '.' just like the below figure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let a = 10;&lt;BR /&gt;%macro filter_age(age_start, age_end);&lt;BR /&gt;&lt;BR /&gt;%local today_;&lt;BR /&gt;%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0), date9.);&lt;/P&gt;&lt;P&gt;proc sql outobs = &amp;amp;a;&lt;BR /&gt;create table filter_age as&lt;BR /&gt;select distinct cif_num, yrdif(birth_dt, "&amp;amp;today_"d, 'actual') as age&lt;BR /&gt;from test&lt;/P&gt;&lt;P&gt;where calcuated age between &amp;amp;age_start and &amp;amp;age_end&lt;BR /&gt;quit;&lt;BR /&gt;%mend filter_age;&lt;BR /&gt;%filter_age(10, 20);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EvansHsieh_0-1608782613234.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52999iA5366860B797DEB0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EvansHsieh_0-1608782613234.png" alt="EvansHsieh_0-1608782613234.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 04:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708034#M217496</guid>
      <dc:creator>EvansHsieh</dc:creator>
      <dc:date>2020-12-24T04:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708046#M217502</link>
      <description>&lt;P&gt;I think your code has syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there errors in log windows?&lt;/P&gt;
&lt;P&gt;You're trying to test this code, aren't you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 1. calcuated=&amp;gt;CALCUATED */
/* 2. Semicolon at the end of sql procedure */
where CALCULATED age between &amp;amp;age_start and &amp;amp;age_end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 07:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708046#M217502</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2020-12-24T07:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708047#M217503</link>
      <description>&lt;P&gt;What format do you expect that &amp;amp;toady_ will be?&lt;/P&gt;
&lt;P&gt;Add &lt;STRONG&gt;%put &amp;amp;today_&lt;/STRONG&gt;&amp;nbsp; after the line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0), date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I assume you miss function PUT in above line.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 07:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708047#M217503</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-24T07:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708048#M217504</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact, the figure was generated from&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;%macro filter_age(age_start, age_end);&lt;BR /&gt;%local today_;&lt;BR /&gt;%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0), date9.);&lt;/P&gt;&lt;P&gt;proc sql outobs = &amp;amp;a;&lt;BR /&gt;create table filter_age as&lt;BR /&gt;select distinct cif_num, yrdif(birth_dt, "&amp;amp;today_"d, 'actual') as age&lt;BR /&gt;from test&lt;BR /&gt;quit;&lt;BR /&gt;%mend filter_age;&lt;BR /&gt;%filter_age(10, 20);&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;"test" data is&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;CIF_Num Birth_Dt &lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;12NOV1993&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;16AUG1976&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;29OCT1964&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;and what my expected is that after input the age interval, I can create a table including all of information about this specific generation. That is why I add "&lt;SPAN&gt;where calcuated age between &amp;amp;age_start and &amp;amp;age_end&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 08:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708048#M217504</guid>
      <dc:creator>EvansHsieh</dc:creator>
      <dc:date>2020-12-24T08:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708052#M217506</link>
      <description>Beacuse I want to create table by&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;proc sql outobs = 10;&lt;BR /&gt;create table filter_age as&lt;BR /&gt;select distinct cif_num, yrdif(birth_dt, today() 'actual') as age&lt;BR /&gt;from test;&lt;BR /&gt;quit;&lt;BR /&gt;------------------------------------&lt;BR /&gt;but if I wanna put it in macro function, i need to transform "today()" into macro variables. Also, i'm quit sure how can i apply with "yrdif" function in macro.</description>
      <pubDate>Thu, 24 Dec 2020 08:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708052#M217506</guid>
      <dc:creator>EvansHsieh</dc:creator>
      <dc:date>2020-12-24T08:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708054#M217508</link>
      <description>&lt;P&gt;Next code works fine. I have added a test row:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 infile cards dlm='09'x;
 input CIF_Num  Birth_Dt date9.;
cards;
123	12NOV1993
1234	16AUG1976
12345	29OCT1964
77777	20MAY2005
; run;

%let a = 10;
%macro filter_age(age_start, age_end);

%local today_;
%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0), date9.);
%put TODAY_ = &amp;amp;today_;
proc sql outobs = &amp;amp;a;
create table filter_age as
select distinct cif_num, yrdif(birth_dt, "&amp;amp;today_"d, 'actual') as age
from test
where calculated age between &amp;amp;age_start and &amp;amp;age_end;
quit;
%mend filter_age;
%filter_age(10, 20);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Dec 2020 08:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708054#M217508</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-24T08:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708063#M217513</link>
      <description>&lt;P&gt;Save yourself some potential future trouble and some typing by not formatting macro variables taht will be used for arithmetic or logical operations. See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;. (You still need to format them if you need a human to read the values)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today_ = %sysfunc(intnx(year, %sysfunc(today()), 0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct cif_num, yrdif(birth_dt, &amp;amp;today_, 'actual') as age&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This formatting of macro variables is unnecessary and seems to cause lots of people problems. (Of course, the other points made by the other replies are still valid and required to make this code work.)&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 11:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708063#M217513</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-24T11:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can i calculate  age by "yrdif" in macro function ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708071#M217519</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro filter_age(age_start, age_end);

%local today_;
%let today_ = %sysfunc(today());
proc sql outobs = &amp;amp;a;
create table filter_age as
  select
  distinct cif_num,
  yrdif(birth_dt, &amp;amp;today_.,'actual') as age
  from test
  where calcuated age between &amp;amp;age_start and &amp;amp;age_end
;
quit;
%mend filter_age;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro variables need no formats (Maxim 28), and the INTNX function with a value of 0 and no modifier will result in an unchanged value. In case this does not lead to the expected result, please post the log.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 12:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-calculate-age-by-quot-yrdif-quot-in-macro-function/m-p/708071#M217519</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-24T12:42:12Z</dc:date>
    </item>
  </channel>
</rss>

