<?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: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847249#M334984</link>
    <description>&lt;P&gt;SAS makes its own rules. Whatever you learned from those other 8 programming languages may or may not apply to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding "&lt;SPAN&gt;an unclear distinction between integer and non-integer logical operations"&lt;/SPAN&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; says so clearly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H1 id="p1d9ypna2tpt16n1xam57kuffcpt" class="xisDoc-title"&gt;%SYSEVALF Macro Function&lt;/H1&gt;
&lt;P class="xisDoc-shortDescription"&gt;Evaluates arithmetic and logical expressions using floating-point arithmetic.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Thu, 01 Dec 2022 13:52:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-12-01T13:52:11Z</dc:date>
    <item>
      <title>Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846879#M334797</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;new here! I'd like to know why this example works on SAS Studio&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro test_macro();
    %let a = 1.0;
    %let b = 2.0;

    %let delta = %sysevalf(&amp;amp;a. - &amp;amp;b.);
    %put delta = &amp;amp;delta.;

    %if &amp;amp;delta. &amp;lt;= 0.0 %then %do;
        %put delta is NEGATIVE;
    %end;
%mend test_macro;

%test_macro();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;while instead the following code&amp;nbsp;produces an error.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro test_macro();
    %let a = 0.1;
    %let b = 0.11;

    %let delta = %sysevalf(&amp;amp;a. - &amp;amp;b.);
    %put delta = &amp;amp;delta.;

    %if &amp;amp;delta. &amp;lt;= 0.0 %then %do;
        %put delta is NEGATIVE;
    %end;
%mend test_macro;

%test_macro();&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The 
        condition was: &amp;amp;delta. &amp;lt;= 0.0 
 ERROR: The macro TEST_MACRO will stop executing.&lt;/PRE&gt;&lt;P&gt;Is there any solution available?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 18:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846879#M334797</guid>
      <dc:creator>caerbannog</dc:creator>
      <dc:date>2022-11-29T18:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846889#M334802</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test_macro();
    %let a = 0.1;
    %let b = 0.11;

    %let delta = %sysevalf(&amp;amp;a. - &amp;amp;b.);
    %put delta = &amp;amp;delta.;

    %if %sysevalf(&amp;amp;delta. &amp;lt;= 0.0) %then %do;
        %put delta is NEGATIVE;
    %end;
%mend test_macro;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Without the %sysevalf, the macro processor doesn't do non-integer arithmetic.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 18:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846889#M334802</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-29T18:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846894#M334806</link>
      <description>&lt;P&gt;You show that you understand how to force the macro processor to handle non-integer arithmetic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %let delta = %sysevalf(&amp;amp;a. - &amp;amp;b.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So why didn't you use that later on?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %if %sysevalf(&amp;amp;delta. &amp;lt;= 0.0) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 19:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/846894#M334806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T19:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847246#M334981</link>
      <description>It works, thank you!</description>
      <pubDate>Thu, 01 Dec 2022 13:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847246#M334981</guid>
      <dc:creator>caerbannog</dc:creator>
      <dc:date>2022-12-01T13:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847248#M334983</link>
      <description>Even though I've been able to put together that example, I haven't written the original code but I've been asked to maintain it and run it. I'm familiar with 8 programming languages and proficient (professionally) with at least half of them. Still, I think this is the only case where I've seen such an unclear distinction between integer and non-integer logical operations, and the error message tells something about a character operand. In addition, 1.0, 2.0 and 0.0 might look like integers to a human being, but usually, a parser should interpret them as non-integer numbers, so I also assumed that was the case for SAS.</description>
      <pubDate>Thu, 01 Dec 2022 13:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847248#M334983</guid>
      <dc:creator>caerbannog</dc:creator>
      <dc:date>2022-12-01T13:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847249#M334984</link>
      <description>&lt;P&gt;SAS makes its own rules. Whatever you learned from those other 8 programming languages may or may not apply to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding "&lt;SPAN&gt;an unclear distinction between integer and non-integer logical operations"&lt;/SPAN&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; says so clearly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H1 id="p1d9ypna2tpt16n1xam57kuffcpt" class="xisDoc-title"&gt;%SYSEVALF Macro Function&lt;/H1&gt;
&lt;P class="xisDoc-shortDescription"&gt;Evaluates arithmetic and logical expressions using floating-point arithmetic.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847249#M334984</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-01T13:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in macro produces character operand SAS Studio 3.81 (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847256#M334986</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437372"&gt;@caerbannog&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Even though I've been able to put together that example, I haven't written the original code but I've been asked to maintain it and run it. I'm familiar with 8 programming languages and proficient (professionally) with at least half of them. Still, I think this is the only case where I've seen such an unclear distinction between integer and non-integer logical operations, and the error message tells something about a character operand. In addition, 1.0, 2.0 and 0.0 might look like integers to a human being, but usually, a parser should interpret them as non-integer numbers, so I also assumed that was the case for SAS.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is probably helps to understand that SAS code and macro code are two different languages.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code there is only one type of number, floating point numbers.&amp;nbsp; &amp;nbsp;But in some languages support other type of numbers including integers.&amp;nbsp; Try calculating 5/3 and 5.0/3.0 in one of the languages and see if you get the same results.&amp;nbsp; &amp;nbsp;In SAS code you always get the same answer since SAS only using floating point numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the macro processor is just a text manipulation tool.&amp;nbsp; Everything is a character string to the macro processor.&amp;nbsp; But to support things like %DO loops they needed to include some recognition of numbers.&amp;nbsp; So they build in some integer arithmetic (including integer comparison operators) with the %EVAL() function.&amp;nbsp; That is what is used by %IF and %DO loops to deal with integer arithmetic.&amp;nbsp; Since integers do not need a decimal place, that is why something with a period is seen as a string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To support the occasional need for floating point arithmetic they added the %SYSEVALF() function.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 04:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtraction-in-macro-produces-character-operand-SAS-Studio-3-81/m-p/847256#M334986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-02T04:10:42Z</dc:date>
    </item>
  </channel>
</rss>

