<?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: Multiple less than signs in the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949355#M371385</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/467356"&gt;@Bill3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;for example: Step1: %let tab=3; %macro test(); %if 1&amp;lt;&amp;amp;tab.&amp;lt;4 %then %do; %put it worked; %end; %mend test; %test; Step2: when i modified "%let tab =4; it still prints "it worked".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A couple of tests make me think that the way the SAS Macro processor handles something like 1&amp;lt;3&amp;lt;4 is that it first, left to right, resolves the first comparison: 1&amp;lt;3. Which may return 0 for False or 1 for true. Then uses that result in the &amp;lt;4. So pretty much regardless what the first comparison would be the result is 1 because both 1 and 0 are less than 4.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2024 13:39:35 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-10-29T13:39:35Z</dc:date>
    <item>
      <title>Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949313#M371371</link>
      <description>&lt;P&gt;for example: Step1: %let tab=3; %macro test(); %if 1&amp;lt;&amp;amp;tab.&amp;lt;4 %then %do; %put it worked; %end; %mend test; %test; Step2: when i modified "%let tab =4; it still prints "it worked".&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 04:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949313#M371371</guid>
      <dc:creator>Bill3</dc:creator>
      <dc:date>2024-10-29T04:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949314#M371372</link>
      <description>&lt;P&gt;I couldn't find it in the documentation but using macro language you can't combine comparison operators the way you did.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below syntax will return what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(tab);
/*  %if %eval(1&amp;lt;&amp;amp;tab.&amp;lt;4) %then*/
  %if 1&amp;lt;&amp;amp;tab. and &amp;amp;tab.&amp;lt;4 %then
    %do;
      %put TRUE;
    %end;
  %else %put FALSE;
%mend test;

%test(3);
%test(4);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2024 04:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949314#M371372</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-29T04:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949315#M371373</link>
      <description>sorry, i just want to combine these two operators.</description>
      <pubDate>Tue, 29 Oct 2024 05:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949315#M371373</guid>
      <dc:creator>Bill3</dc:creator>
      <dc:date>2024-10-29T05:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949316#M371374</link>
      <description>&lt;P&gt;Unlike the IF clause in regular SAS data step, the %IF macro statement processes from left to right, which means the expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %IF 1&amp;lt;&amp;amp;tab.&amp;lt;4  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;first evaluates the &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;1&amp;lt;&amp;amp;tab&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; component.&amp;nbsp; &amp;nbsp;When macrovar &amp;amp;TAB equals 3, this component resolves to 1 (for true).&amp;nbsp; When macrovar &amp;amp;TAB is, say 0, this component resolves to 0 (for false).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it tests whether that resolved value is less than 4, which is also true (because both 0 and 1 are &amp;lt;4).&amp;nbsp; In fact, for any &amp;amp;TAB value, the &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;%IF 1&amp;lt;&amp;amp;tab.&amp;lt;4&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&amp;nbsp;macro test will always be true.&amp;nbsp;&amp;nbsp;&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;
&lt;P&gt;But as you no doubt know, this is NOT the behavior of the non-macro IF statement, which imputes an implicit AND operator when you have the&amp;nbsp;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;if value1 relop value2 relop value3&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&amp;nbsp;structure (where "relop" means relational operator).&amp;nbsp; So the expression&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if  1&amp;lt;%tab.&amp;lt;4&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is interpreted as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if  1&amp;lt;&amp;amp;tab.  AND &amp;amp;tab&amp;lt;4&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2024 05:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949316#M371374</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-29T05:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949317#M371375</link>
      <description>It seems quite reasonable. So there's no way to combine these two relop in %if?</description>
      <pubDate>Tue, 29 Oct 2024 05:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949317#M371375</guid>
      <dc:creator>Bill3</dc:creator>
      <dc:date>2024-10-29T05:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949318#M371376</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/467356"&gt;@Bill3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;It seems quite reasonable. So there's no way to combine these two relop in %if?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I believe you will have to insert the AND operator, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %if 1&amp;lt;&amp;amp;tab.  AND &amp;amp;tab.&amp;lt;4 %then %do; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 05:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949318#M371376</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-29T05:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949349#M371382</link>
      <description>&lt;P&gt;In the language of normal SAS code you can abbreviate an expression in the form:&lt;/P&gt;
&lt;PRE&gt;(A op1 B) and (B op2 C)&lt;/PRE&gt;
&lt;P&gt;By removing the AND and the duplicate value/variable to get:&lt;/P&gt;
&lt;PRE&gt;A op1 B op2 C&lt;/PRE&gt;
&lt;P&gt;But the language used by &lt;STRONG&gt;the MACRO PROCESSOR does NOT support that abbreviated syntax&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a question about how to expand an abbreviated expression you can use it in a WHERE statement and SAS will echo to restructured syntax in the log.&lt;/P&gt;
&lt;PRE&gt;1    data want;
2      set sashelp.class;
3      where age &amp;lt; height &amp;lt; weight ;
4    run;

NOTE: There were 18 observations read from the data set SASHELP.CLASS.
      WHERE (age&amp;lt;height) and (height&amp;lt;weight);
NOTE: The data set WORK.WANT has 18 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2024 12:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949349#M371382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-29T12:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple less than signs in the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949355#M371385</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/467356"&gt;@Bill3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;for example: Step1: %let tab=3; %macro test(); %if 1&amp;lt;&amp;amp;tab.&amp;lt;4 %then %do; %put it worked; %end; %mend test; %test; Step2: when i modified "%let tab =4; it still prints "it worked".&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A couple of tests make me think that the way the SAS Macro processor handles something like 1&amp;lt;3&amp;lt;4 is that it first, left to right, resolves the first comparison: 1&amp;lt;3. Which may return 0 for False or 1 for true. Then uses that result in the &amp;lt;4. So pretty much regardless what the first comparison would be the result is 1 because both 1 and 0 are less than 4.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 13:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-less-than-signs-in-the-macro/m-p/949355#M371385</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-29T13:39:35Z</dc:date>
    </item>
  </channel>
</rss>

