<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327225#M271660</link>
    <description>&lt;P&gt;I can see several problems there.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You haven't defined the parameters in your macro definition - calling the macro with them when they haven't been defined will cause an error&lt;/LI&gt;
&lt;LI&gt;The&amp;nbsp;&lt;EM&gt;if&lt;/EM&gt;&amp;nbsp;condition doesn't work like that for macro code, sadly; you have to expand it&lt;/LI&gt;
&lt;LI&gt;The way you're referring to&amp;nbsp;&lt;EM&gt;dep&lt;/EM&gt; is wrong - you're referring to the value of dep, not to the macro variable itself.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO a(indep=, i=);
%if %eval(&amp;amp;i &amp;gt;= 1 and &amp;amp;i &amp;lt;= 10)
    %then %let dep = bi;
    %else %if %eval(&amp;amp;i &amp;gt;= 11 and &amp;amp;i &amp;lt;= 20)
    %then %let dep = bi2;
    %else %if %eval(&amp;amp;i &amp;gt;= 21 and &amp;amp;i &amp;lt;= 30)
    %then %let dep = bi3;
PROC LOGISTIC DATA = x;
MODEL &amp;amp;dep (REF = "Yes")= &amp;amp;indep;
RUN;
%MEND a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp;&lt;EM&gt;%eval&lt;/EM&gt; isn't strictly necessary, but I always use it - it tends to pick up typing mistakes faster that I inevitably introduce to my code! I also like to use&amp;nbsp;&lt;EM&gt;%else&lt;/EM&gt; like this, where the conditions are mutually exclusive; sadly macro code doesn't have a %select statement.&amp;nbsp;(Indentation like this not obligatory, of course…)&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2017 00:13:59 GMT</pubDate>
    <dc:creator>LaurieF</dc:creator>
    <dc:date>2017-01-25T00:13:59Z</dc:date>
    <item>
      <title>MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327223#M271658</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to set up a macro to&amp;nbsp;run quite a few&amp;nbsp;logistic regression models. My question is how to I code it in such a way that&lt;/P&gt;&lt;P&gt;for the first 10 models, the macro would use bi as the dependent variable, for the next 10 models, use bi2 as the dependent variable etc.&lt;/P&gt;&lt;P&gt;The codes highlighted in &lt;FONT color="#ff00ff"&gt;purple&lt;/FONT&gt; wouldnt work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO a;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff00ff"&gt;%IF 1 &amp;lt;= &amp;amp;i &amp;lt;=&amp;nbsp;10&lt;/FONT&gt; %THEN %DO; %LET &amp;amp;dep = bi; %END;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff00ff"&gt;%IF 11 &amp;lt;= &amp;amp;i &amp;lt;=&amp;nbsp;20&lt;/FONT&gt; %THEN %DO; %LET &amp;amp;dep = bi2; %END;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff00ff"&gt;%IF 21 &amp;lt;= &amp;amp;i &amp;lt;=&amp;nbsp;30&lt;/FONT&gt; %THEN %DO; %LET &amp;amp;dep = bi3; %END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC LOGISTIC DATA = x;&lt;/P&gt;&lt;P&gt;MODEL &amp;amp;dep (REF = "Yes")= &amp;amp;indep;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;%MEND a;&lt;/P&gt;&lt;P&gt;%a(indep = mde, i = 1)&lt;/P&gt;&lt;P&gt;%a (indep = pds, i = 2)&lt;/P&gt;&lt;P&gt;%a (indep = pts, i = 3)&lt;/P&gt;&lt;P&gt;%a (indep = so, i = 4)&lt;/P&gt;&lt;P&gt;%a (indep = sp, i = 5)&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;%a(indep = pe, i = 30)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any input is much appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 23:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327223#M271658</guid>
      <dc:creator>clim072</dc:creator>
      <dc:date>2017-01-24T23:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327224#M271659</link>
      <description>&lt;P&gt;The %IF statement, really the implied %EVAL() function call, will not convert&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A &amp;lt;= B &amp;lt;= C&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(A&amp;lt;=B) and (B&amp;lt;=C)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;like the IF statement will. &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to do that yourself.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327224#M271659</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-01-25T00:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327225#M271660</link>
      <description>&lt;P&gt;I can see several problems there.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You haven't defined the parameters in your macro definition - calling the macro with them when they haven't been defined will cause an error&lt;/LI&gt;
&lt;LI&gt;The&amp;nbsp;&lt;EM&gt;if&lt;/EM&gt;&amp;nbsp;condition doesn't work like that for macro code, sadly; you have to expand it&lt;/LI&gt;
&lt;LI&gt;The way you're referring to&amp;nbsp;&lt;EM&gt;dep&lt;/EM&gt; is wrong - you're referring to the value of dep, not to the macro variable itself.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO a(indep=, i=);
%if %eval(&amp;amp;i &amp;gt;= 1 and &amp;amp;i &amp;lt;= 10)
    %then %let dep = bi;
    %else %if %eval(&amp;amp;i &amp;gt;= 11 and &amp;amp;i &amp;lt;= 20)
    %then %let dep = bi2;
    %else %if %eval(&amp;amp;i &amp;gt;= 21 and &amp;amp;i &amp;lt;= 30)
    %then %let dep = bi3;
PROC LOGISTIC DATA = x;
MODEL &amp;amp;dep (REF = "Yes")= &amp;amp;indep;
RUN;
%MEND a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp;&lt;EM&gt;%eval&lt;/EM&gt; isn't strictly necessary, but I always use it - it tends to pick up typing mistakes faster that I inevitably introduce to my code! I also like to use&amp;nbsp;&lt;EM&gt;%else&lt;/EM&gt; like this, where the conditions are mutually exclusive; sadly macro code doesn't have a %select statement.&amp;nbsp;(Indentation like this not obligatory, of course…)&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 00:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327225#M271660</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-01-25T00:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327241#M271661</link>
      <description>&lt;P&gt;Since you have control of &amp;amp;i as a parameter, you don't really need to safeguard against unusual values. &amp;nbsp;You could simplify this to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;i &amp;lt;= 10 %then %let dep = bi;&lt;/P&gt;
&lt;P&gt;%else %if &amp;amp;i &amp;lt;= 20 then %let dep = bi2;&lt;/P&gt;
&lt;P&gt;%else %let dep = bi3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's remotely possibly that the original %LET statements were correct. &amp;nbsp;More likely, the %LET statements should assign a value to DEP (as illustrated above), not to &amp;amp;DEP (as in your original code).&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 03:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO/m-p/327241#M271661</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-25T03:30:54Z</dc:date>
    </item>
  </channel>
</rss>

