<?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: macro with %if %then statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193141#M36361</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make sure to reference your variables properly:&lt;/P&gt;&lt;P&gt;%if num_month &amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;should be&lt;/P&gt;&lt;P&gt;%if &amp;amp;num_month &amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BUT&lt;/P&gt;&lt;P&gt;you probably mean&lt;/P&gt;&lt;P&gt;%if &amp;amp;i&amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;%if &amp;amp;i= 12 then do;&lt;/P&gt;&lt;P&gt;As you do not change the value for &amp;amp;nummonth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this were my project I would consider passing a start and end date and then parse over those using the date incrementing function INTNX and put using a selected format to build the names you're using. Then I would not have a problem with any period of reports (providing the data of the appropriate month year combinations exist.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Jun 2015 23:20:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-06-30T23:20:55Z</dc:date>
    <item>
      <title>macro with %if %then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193140#M36360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following code that is working correctly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro new_tran;&lt;/P&gt;&lt;P&gt;data new_tran;&lt;/P&gt;&lt;P&gt;set&lt;/P&gt;&lt;P&gt;%do i = 01 %to &amp;amp;num_month;&lt;/P&gt;&lt;P&gt;%let val=%sysfunc(putn(&amp;amp;i,z2.));&lt;/P&gt;&lt;P&gt;newtran.pid_defaults_final_&amp;amp;val.&amp;amp;year &lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%new_tran;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to add something like this:&lt;/P&gt;&lt;P&gt;%if &amp;amp;num_month = 12 %then &amp;amp;year= &amp;amp;year - 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to use %eval() but I couldn't get it to work.&amp;nbsp; &amp;amp;num_month = month(year()) -1.&amp;nbsp; I want to make sure that next January when the report runs for December that it takes the correct year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the following but it's really just a guess as I'm not that experienced with macros.&amp;nbsp; Any help will be appreciated:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro new_tran (num_month=12, year=2015);&lt;/P&gt;&lt;P&gt;%do i = 01 %to &amp;amp;num_month;&lt;/P&gt;&lt;P&gt;%let val=%sysfunc(putn(&amp;amp;i,z2.));&lt;/P&gt;&lt;P&gt;%let year_1 = %eval(&amp;amp;year -1);&lt;/P&gt;&lt;P&gt;%if num_month &amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;%put pid_defaults_final_&amp;amp;val.&amp;amp;year;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if num_month = 12 %then %do;&lt;/P&gt;&lt;P&gt;%put pid_defaults_final_&amp;amp;val.&amp;amp;year_1;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%new_tran;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 22:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193140#M36360</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-30T22:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: macro with %if %then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193141#M36361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make sure to reference your variables properly:&lt;/P&gt;&lt;P&gt;%if num_month &amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;should be&lt;/P&gt;&lt;P&gt;%if &amp;amp;num_month &amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BUT&lt;/P&gt;&lt;P&gt;you probably mean&lt;/P&gt;&lt;P&gt;%if &amp;amp;i&amp;lt; 12 %then %do;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;%if &amp;amp;i= 12 then do;&lt;/P&gt;&lt;P&gt;As you do not change the value for &amp;amp;nummonth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this were my project I would consider passing a start and end date and then parse over those using the date incrementing function INTNX and put using a selected format to build the names you're using. Then I would not have a problem with any period of reports (providing the data of the appropriate month year combinations exist.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 23:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193141#M36361</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-06-30T23:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: macro with %if %then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193142#M36362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Makes perfect sense.&amp;nbsp; Just tested it, thanks for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 23:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-with-if-then-statement/m-p/193142#M36362</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-30T23:35:27Z</dc:date>
    </item>
  </channel>
</rss>

