<?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: SAS not liking negative decimals! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516441#M139478</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220407"&gt;@EvoluZion3&lt;/a&gt;&amp;nbsp;wrote:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro compare(a,b);
   %let y=%sysevalf(&amp;amp;a-&amp;amp;b);
   %put &amp;amp;a - &amp;amp;b = &amp;amp;y;
	 %if &amp;amp;y &amp;gt; 0 %then %do; %put hello; %end;
%mend compare;

%compare(5, 1); /* +ve (works) */
%compare(1, 5); /* -ve (works) */
&lt;FONT color="#FF0000"&gt;%compare(5, 2.3); /* +ve decimal (works) */&lt;/FONT&gt;
%compare(2.3, 5); /* -ve decimal (doesn't work) */

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For all four run-throughs the maths works fine (evidenced by the %put command) ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that without %SYSEVALF positive &lt;EM&gt;non-integers&lt;/EM&gt;&amp;nbsp;(more precisely: numbers involving a decimal point or other non-digit characters, including 1.0, 1E6, etc.) are compared &lt;EM&gt;as character strings&lt;/EM&gt;. Change the %IF condition to &lt;FONT face="courier new,courier"&gt;&amp;amp;y &amp;gt; &lt;STRONG&gt;10&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;and rerun the third macro call (after compiling the modified macro) to see that it's &lt;EM&gt;not&lt;/EM&gt; maths that "works" here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without %SYSEVALF, such a "character string" after a minus sign (indicating that what follows is a number) is refused as a "character operand ... where a numeric operand is required" (see error message).&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 18:14:17 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-11-27T18:14:17Z</dc:date>
    <item>
      <title>Decimal comparison not working in SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516399#M139465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure this is my fault but I don't know what's going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run the below code, the simple macro function will evaluate A - B into Y, and then do a dummy comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro compare(a,b);
   %let y=%sysevalf(&amp;amp;a-&amp;amp;b);
   %put &amp;amp;a - &amp;amp;b = &amp;amp;y;
	 %if &amp;amp;y &amp;gt; 0 %then %do; %put hello; %end;
%mend compare;

%compare(5, 1); /* +ve (works) */
%compare(1, 5); /* -ve (works) */
%compare(5, 2.3); /* +ve decimal (works) */
%compare(2.3, 5); /* -ve decimal (doesn't work) */

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For all four run-throughs the maths works fine (evidenced by the %put command), however the "%if &amp;amp;y &amp;gt; 0" line fails on the last run-through, when the result of the subtraction is both negative and a decimal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get this for the fourth run-through (in the log):&lt;/P&gt;
&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&amp;nbsp;&amp;nbsp; &amp;amp;y&amp;nbsp;&amp;gt; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What on earth is happening!?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 17:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516399#M139465</guid>
      <dc:creator>EvoluZion3</dc:creator>
      <dc:date>2018-11-27T17:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not liking negative decimals!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516403#M139466</link>
      <description>&lt;P&gt;Use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysevalf(&amp;amp;y &amp;gt; 0,boolean) %then %do; %put hello; %end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macros are just text processors, they can get confused easily, and you have to take special care to make sure things work when performing arithmetic or Boolean comparisons.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516403#M139466</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-27T16:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not liking negative decimals!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516408#M139467</link>
      <description>Thank you very much Paige, that's worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516408#M139467</guid>
      <dc:creator>EvoluZion3</dc:creator>
      <dc:date>2018-11-27T16:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not liking negative decimals!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516411#M139468</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro compare(a,b);
   %let y=%sysevalf(&amp;amp;a-&amp;amp;b);
   %put &amp;amp;a - &amp;amp;b = &amp;amp;y;
	 %if %sysevalf(&amp;amp;y &amp;gt; 0) %then %do; %put hello; %end;
	 %else %put good bye;
%mend compare;


%compare(2.3, 5); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516411#M139468</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-27T16:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS not liking negative decimals!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516441#M139478</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220407"&gt;@EvoluZion3&lt;/a&gt;&amp;nbsp;wrote:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro compare(a,b);
   %let y=%sysevalf(&amp;amp;a-&amp;amp;b);
   %put &amp;amp;a - &amp;amp;b = &amp;amp;y;
	 %if &amp;amp;y &amp;gt; 0 %then %do; %put hello; %end;
%mend compare;

%compare(5, 1); /* +ve (works) */
%compare(1, 5); /* -ve (works) */
&lt;FONT color="#FF0000"&gt;%compare(5, 2.3); /* +ve decimal (works) */&lt;/FONT&gt;
%compare(2.3, 5); /* -ve decimal (doesn't work) */

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For all four run-throughs the maths works fine (evidenced by the %put command) ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that without %SYSEVALF positive &lt;EM&gt;non-integers&lt;/EM&gt;&amp;nbsp;(more precisely: numbers involving a decimal point or other non-digit characters, including 1.0, 1E6, etc.) are compared &lt;EM&gt;as character strings&lt;/EM&gt;. Change the %IF condition to &lt;FONT face="courier new,courier"&gt;&amp;amp;y &amp;gt; &lt;STRONG&gt;10&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;and rerun the third macro call (after compiling the modified macro) to see that it's &lt;EM&gt;not&lt;/EM&gt; maths that "works" here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without %SYSEVALF, such a "character string" after a minus sign (indicating that what follows is a number) is refused as a "character operand ... where a numeric operand is required" (see error message).&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 18:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decimal-comparison-not-working-in-SAS-macro/m-p/516441#M139478</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-27T18:14:17Z</dc:date>
    </item>
  </channel>
</rss>

