<?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 %if %then in a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MAcro-if-then-in-a-loop/m-p/337917#M76822</link>
    <description>&lt;P&gt;Here is one example. Note that where I have %put you would put your report code.&lt;/P&gt;
&lt;PRE&gt;%macro dummy(parm);
%if &amp;amp;parm = a %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=b %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=c %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=d %then %do;
   %put Parm= &amp;amp;parm;
%end;
%put Done;
%mend;

%dummy(a);
%dummy(b);
%dummy(c);
%dummy(d);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also recommend against using "a" with macros unless there is an extremely good reason.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2017 17:26:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-03T17:26:17Z</dc:date>
    <item>
      <title>MAcro %if %then in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-if-then-in-a-loop/m-p/337913#M76819</link>
      <description>&lt;P&gt;I am working with a macro loop that I want to spit out slightly different reports based on the current where variable up in the loop. All three reports are very similar proc reports, just different variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;simplifying here, as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Loop begins.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%IF error="a" %then %do ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;report 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%IF error="&lt;/SPAN&gt;&lt;SPAN&gt;b&lt;/SPAN&gt;&lt;SPAN&gt;" %then %do ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;report 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%else %&amp;nbsp;%do ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;report3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I can only get this to work with one&amp;nbsp;%if %then and an %else--2 reports. How can I add in another %if statement to allow for a 3rd option, since this is a loop that goes through several 'errors.' I have tried several variations, but can't get passed a single if/then and else combo.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-if-then-in-a-loop/m-p/337913#M76819</guid>
      <dc:creator>sasiscool</dc:creator>
      <dc:date>2017-03-03T17:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro %if %then in a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-if-then-in-a-loop/m-p/337917#M76822</link>
      <description>&lt;P&gt;Here is one example. Note that where I have %put you would put your report code.&lt;/P&gt;
&lt;PRE&gt;%macro dummy(parm);
%if &amp;amp;parm = a %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=b %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=c %then %do;
   %put Parm= &amp;amp;parm;
%end;
%else %if &amp;amp;parm=d %then %do;
   %put Parm= &amp;amp;parm;
%end;
%put Done;
%mend;

%dummy(a);
%dummy(b);
%dummy(c);
%dummy(d);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also recommend against using "a" with macros unless there is an extremely good reason.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 17:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-if-then-in-a-loop/m-p/337917#M76822</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-03T17:26:17Z</dc:date>
    </item>
  </channel>
</rss>

