<?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: %if %then %else for macrovariable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831536#M328616</link>
    <description>&lt;P&gt;And it's important to know that %EVAL is implicitly called by %IF, because it explains surprises like:&lt;/P&gt;
&lt;PRE&gt;1    %macro a();
2       %if 10.1 &amp;lt; 2 %then %put 10.1 is less than two!?! ;
3    %mend;
4    %a()
10.1 is less than two!?!
&lt;/PRE&gt;
&lt;P&gt;If you give an %IF statement a string that it thinks is a numeric expression, sometimes you'll get an error which shows that %EVAL is being called, e.g.:&lt;/P&gt;
&lt;PRE&gt;6    %macro b();
7       %if Q+1=Q+1 %then %put Equal ;
8    %mend;
9    %b()
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: Q+1=Q+1
ERROR: The macro B will stop executing.
&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Sep 2022 12:18:05 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2022-09-02T12:18:05Z</dc:date>
    <item>
      <title>%if %then %else for macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831510#M328601</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value of my macrovariable&amp;nbsp;%put TEST &amp;amp;resultat. is 4.&lt;/P&gt;
&lt;P&gt;I would like to do the test :&amp;nbsp;%if %eval(&amp;amp;resultat.&amp;lt;4) %then&lt;BR /&gt;%do; .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My question is : do I need to write the %eval or I can just write&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;%if&amp;nbsp; &amp;amp;resultat.&amp;lt;4 %then&lt;BR /&gt;%do; ..... because it seems to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help !&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 08:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831510#M328601</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-09-02T08:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else for macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831511#M328602</link>
      <description>&lt;P&gt;In the meantime, is it possible to upload the code before and after?&lt;BR /&gt;Normally, %eval is not necessary if such a value is stored in a macro variable.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You could run the following code and check the logs to see how SAS is processing the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Sep 2022 08:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831511#M328602</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-09-02T08:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else for macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831512#M328603</link>
      <description>&lt;P&gt;No, you do not need to write the %Eval Function explicitly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason you do not have to is that SAS calls the %Eval Function implicitly behind the scenes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a;
   %if 1 + 1 = 2 %then %put One plus one equals two!;
%mend;
 
%a&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the same as this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro b;
   %if %eval(1 + 1 = 2) %then %put one plus one equals two!;
%mend;
 
%b&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 08:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831512#M328603</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-02T08:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else for macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831536#M328616</link>
      <description>&lt;P&gt;And it's important to know that %EVAL is implicitly called by %IF, because it explains surprises like:&lt;/P&gt;
&lt;PRE&gt;1    %macro a();
2       %if 10.1 &amp;lt; 2 %then %put 10.1 is less than two!?! ;
3    %mend;
4    %a()
10.1 is less than two!?!
&lt;/PRE&gt;
&lt;P&gt;If you give an %IF statement a string that it thinks is a numeric expression, sometimes you'll get an error which shows that %EVAL is being called, e.g.:&lt;/P&gt;
&lt;PRE&gt;6    %macro b();
7       %if Q+1=Q+1 %then %put Equal ;
8    %mend;
9    %b()
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: Q+1=Q+1
ERROR: The macro B will stop executing.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Sep 2022 12:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831536#M328616</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-09-02T12:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: %if %then %else for macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831642#M328660</link>
      <description>&lt;P&gt;One could argue that using %eval() explicitly is not a bad thing as then it's directly visible in the code what's happening.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a();
   %if 10.1 &amp;lt; 2             %then %put Test1a: 10.1 is less than two!?! ;
   %if %eval(10.1 &amp;lt; 2)      %then %put Test2a: 10.1 is less than two!?! ;
   %if %sysevalf(10.1 &amp;lt; 2)  %then %put Test3a: 10.1 is less than two!?! ;
   %if 10 &amp;lt; 2               %then %put Test4a: 10   is less than two!?! ;

   %if 2 &amp;lt; 10.1             %then %put Test1b: Two is less than 10.1!?! ;
   %if %eval(2 &amp;lt; 10.1)      %then %put Test2b: Two is less than 10.1!?! ;
   %if %sysevalf(2 &amp;lt; 10.1)  %then %put Test3b: Two is less than 10.1!?! ;
   %if 2 &amp;lt; 10               %then %put Test4b: Two   is less than 10!?! ;

%mend;
%a()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1662180173159.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74972i0DA06A4E1B49A091/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1662180173159.png" alt="Patrick_0-1662180173159.png" /&gt;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 04:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-for-macrovariable/m-p/831642#M328660</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-03T04:43:29Z</dc:date>
    </item>
  </channel>
</rss>

