<?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: Global macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104259#M29127</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to use double quotes...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Age = INT((INTCK('month', DOB,"31mar&amp;amp;year2."d) - (DAY(DOB)&amp;gt;DAY("31mar&amp;amp;year2."d)))/12);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jul 2012 07:53:38 GMT</pubDate>
    <dc:creator>shivas</dc:creator>
    <dc:date>2012-07-11T07:53:38Z</dc:date>
    <item>
      <title>Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104258#M29126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a new macro variable (year+1) based on the macro year variable (2009-2012) and apply the new macro variable to the age calculation - that is, for 2009 data, the age calculation should be based the fiscal year end, that is March 2010, etc. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,'31mar&amp;amp;year2.'d) - (DAY(DOB)&amp;gt;DAY('31mar&amp;amp;year2.'d)))/12);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought it would work but it didn't; SAS didn't recognize the year2 variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro service_age ();&lt;/P&gt;&lt;P&gt;%do year=2009 %to 2011;&lt;/P&gt;&lt;P&gt;data list&amp;amp;year; merge&amp;nbsp; dob_data (in=a)&amp;nbsp;&amp;nbsp; service&amp;amp;year (in=b); by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let year2=1+&amp;amp;year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,'31mar&amp;amp;year2.'d) - (DAY(DOB)&amp;gt;DAY('31mar&amp;amp;year2.'d)))/12);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend service_age;&lt;/P&gt;&lt;P&gt;%service_age;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I don't use macro, it'd look like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data list2009; merge&amp;nbsp; dob_data (in=a)&amp;nbsp;&amp;nbsp; service2009 (in=b); by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,'31mar2010'd) - (DAY(DOB)&amp;gt;DAY('31mar2010'd)))/12);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data list2010; merge&amp;nbsp; dob_data (in=a)&amp;nbsp;&amp;nbsp; service2010 (in=b); by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,'31mar2011'd) - (DAY(DOB)&amp;gt;DAY('31mar2011'd)))/12);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data list2011; merge&amp;nbsp; dob_data (in=a)&amp;nbsp;&amp;nbsp; service2011 (in=b); by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,'31mar2012'd) - (DAY(DOB)&amp;gt;DAY('31mar2012'd)))/12);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 07:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104258#M29126</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-07-11T07:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104259#M29127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to use double quotes...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Age = INT((INTCK('month', DOB,"31mar&amp;amp;year2."d) - (DAY(DOB)&amp;gt;DAY("31mar&amp;amp;year2."d)))/12);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 07:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104259#M29127</guid>
      <dc:creator>shivas</dc:creator>
      <dc:date>2012-07-11T07:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104260#M29128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a million. It worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 08:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104260#M29128</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-07-11T08:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104261#M29129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macros simply aren't needed here for year2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'31mar&amp;amp;year2.'d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you could use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mdy(3,31,&amp;amp;year+1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My general philosophy is not to use macros if they are not needed. Your loop involving the macro variable &amp;amp;year may or may not be a good use of macros, but even though I can't see your datasets, it seems to me that you don't need a macro here either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 14:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104261#M29129</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2012-07-11T14:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104262#M29130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestion. I changed to using mdy and included sample data below. Let me know if there are ways to improve the code. I've 10 years of data and just use 3 here as an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dob ;&lt;/P&gt;&lt;P&gt;input id dob $8.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 19900314&lt;/P&gt;&lt;P&gt;2 20000413&lt;/P&gt;&lt;P&gt;3 20011201&lt;/P&gt;&lt;P&gt;4 20011201&lt;/P&gt;&lt;P&gt;5 20030915&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data dob_data; set dob;&lt;/P&gt;&lt;P&gt;format dob2 yymmdd10.;&lt;/P&gt;&lt;P&gt;dob2=input(dob,yymmdd10.);&lt;/P&gt;&lt;P&gt;drop dob;&lt;/P&gt;&lt;P&gt;rename dob2=dob;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data service2009; input id;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data service2010; input id;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data service2011; input id;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro service_age ();&lt;/P&gt;&lt;P&gt;%do year=2009 %to 2011;&lt;/P&gt;&lt;P&gt;data list&amp;amp;year; merge&amp;nbsp; dob_data (in=a)&amp;nbsp;&amp;nbsp; service&amp;amp;year (in=b); by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let year2=1+&amp;amp;year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age = INT((INTCK('month', DOB,mdy(3,31,&amp;amp;year.+1) - (DAY(DOB)&amp;gt;DAY(mdy(3,31,&amp;amp;year.+1))))/12));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend service_age;&lt;/P&gt;&lt;P&gt;%service_age;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 18:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104262#M29130</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-07-11T18:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Global macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104263#M29131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm still not convinced that macros are needed here, but without being able to see your data, I don't know for sure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the code you have should work — so it's probably a good idea to use it. You can eliminate the line that says "%let year2=1+&amp;amp;year;"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2012 19:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Global-macro/m-p/104263#M29131</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2012-07-11T19:57:09Z</dc:date>
    </item>
  </channel>
</rss>

