<?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: Conditional logic failed when using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854081#M337558</link>
    <description>Thanks, the :%sysevalf(&amp;amp;_N_ &amp;lt; 100) does the job</description>
    <pubDate>Tue, 17 Jan 2023 12:56:34 GMT</pubDate>
    <dc:creator>Zatere</dc:creator>
    <dc:date>2023-01-17T12:56:34Z</dc:date>
    <item>
      <title>Conditional logic failed when using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854072#M337555</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below conditional logic fails and cannot figure out the reason:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _N_ = 6.3;

%macro test();
	%if &amp;amp;_N_ &amp;lt; 100 %then
		%do;
			%put &amp;amp;_N_ is less than 100;
		%end;
	%else
		%do;
			%put &amp;amp;_N_ is greater than 100;
		%end;
%mend;

%test();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see the logs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28         %let _N_ = 6.3;
29         
30         %macro test();
31         	%if &amp;amp;_N_ &amp;lt; 100 %then
32         		%do;
33         			%put &amp;amp;_N_ is less than 100;
34         		%end;
35         	%else
36         		%do;
37         			%put &amp;amp;_N_ is greater than 100;
38         		%end;
39         %mend;
40         
41         %test();
6.3 is greater than 100&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a workaround:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _N_ = 6.3;

%macro test2();
	%if %sysevalf(&amp;amp;_N_,integer) &amp;lt; 100 %then
		%do;
			%put &amp;amp;_N_ is less than 100;
		%end;
	%else
		%do;
			%put &amp;amp;_N_ is greater than 100;
		%end;
%mend;

%test2();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The logs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28         %let _N_ = 6.3;
29         
30         %macro test2();
31         	%if %sysevalf(&amp;amp;_N_,integer) &amp;lt; 100 %then
32         		%do;
33         			%put &amp;amp;_N_ is less than 100;
34         		%end;
35         	%else
36         		%do;
37         			%put &amp;amp;_N_ is greater than 100;
38         		%end;
39         %mend;
40         
41         %test2();
6.3 is less than 100&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But still I would like to understand the reason..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 11:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854072#M337555</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2023-01-17T11:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional logic failed when using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854078#M337556</link>
      <description>&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/p1d9ypna2tpt16n1xam57kuffcpt.htm" target="_self"&gt;documentation for %SYSEVALF&lt;/A&gt; explains:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Evaluates arithmetic and logical expressions using floating-point arithmetic.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you can't use non-integer arithmetic on macro variables, unless you use %SYSEVALF&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 12:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854078#M337556</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-17T12:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional logic failed when using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854079#M337557</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11100"&gt;@Zatere&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As is described in&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p17i177l3z4kzgn11m7pl8833ch7.htm" target="_blank" rel="noopener"&gt;How the Macro Processor Evaluates Arithmetic Expressions&lt;/A&gt;, the period in "6&lt;FONT size="5" color="#FF0000"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;3" indicates to the macro processor that this string is to be treated as &lt;EM&gt;text&lt;/EM&gt;. As such it is &lt;EM&gt;alphabetically&lt;/EM&gt; &lt;EM&gt;greater&lt;/EM&gt; than the string "100" (or, e.g., than the string "&lt;STRONG&gt;5&lt;/STRONG&gt;999999999"). Without a non-digit character the comparison would be evaluated using &lt;EM&gt;integer arithmetic&lt;/EM&gt;, i.e., 63 &amp;lt; 100 would correctly be true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1d9ypna2tpt16n1xam57kuffcpt.htm" target="_blank" rel="noopener"&gt;%SYSEVALF function&lt;/A&gt;&amp;nbsp;allows for an evaluation&amp;nbsp;using &lt;EM&gt;floating-point&lt;/EM&gt; arithmetic. If this is what you're after, you should put the &lt;EM&gt;entire&lt;/EM&gt; logical expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;amp;_N_ &amp;lt; 100&lt;/FONT&gt; into the argument of %SYSEVALF. Thus it would be evaluated as desired even if &lt;FONT face="courier new,courier"&gt;100&lt;/FONT&gt; was replaced by a non-integer value. For example,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%sysevalf(6.3 &amp;lt; 6.4)&lt;/FONT&gt; would be true and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%sysevalf(6.3 &amp;lt; 6.1)&lt;/FONT&gt; false, whereas&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%sysevalf(6.3, integer)=6&lt;/FONT&gt;&amp;nbsp;and hence is less than &lt;FONT face="courier new,courier"&gt;6.1&lt;/FONT&gt;&amp;nbsp;for the macro processor (string comparison!).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 12:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854079#M337557</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-01-17T12:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional logic failed when using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854081#M337558</link>
      <description>Thanks, the :%sysevalf(&amp;amp;_N_ &amp;lt; 100) does the job</description>
      <pubDate>Tue, 17 Jan 2023 12:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-logic-failed-when-using-macro/m-p/854081#M337558</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2023-01-17T12:56:34Z</dc:date>
    </item>
  </channel>
</rss>

