<?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: Macro conditions gave TRUE or FALSE on same values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491818#M129086</link>
    <description>&lt;P&gt;The macro language is a&amp;nbsp;&lt;EM&gt;code generator&lt;/EM&gt;, which only knows the datatype text, and cannot do calculations on its own, with the exception of integer arithmetic in %if and %do. Therefore the date literals are treated as strings in comparisons.&lt;/P&gt;
&lt;P&gt;'01A is always "smaller" than '01J (in the collating sequence).&lt;/P&gt;
&lt;P&gt;If you follow Maxim 28 and use raw values in the macro variables&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let open_begin = %sysfunc(inputn(20170401,yymmdd8.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the comparisons will work as expected.&lt;/P&gt;</description>
    <pubDate>Sat, 01 Sep 2018 11:10:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-09-01T11:10:51Z</dc:date>
    <item>
      <title>Macro conditions gave TRUE or FALSE on same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491814#M129082</link>
      <description>&lt;P&gt;I was trying to find the difference between the two conditions below, the top one is running fine with TRUE result, but the bottom one always gave me a FALSE&amp;nbsp; result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let open_begin = '01APR2017'd;&lt;BR /&gt;%let open_end = '30JUN2017'd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.../*top one*/&lt;/P&gt;&lt;P&gt;%else %if (&amp;amp;open_begin) ~=&amp;nbsp; &amp;nbsp; and &amp;amp;open_begin &amp;lt;= &amp;amp;open_end&amp;nbsp; %then&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;amp;open_begin &amp;lt;= OPENDATE &amp;lt;= &amp;amp;open_end&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;vs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.../*bottom one*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;open_begin &amp;gt; '01JAN1960'd and &amp;amp;open_end &amp;gt; '01JAN1960'd and &amp;amp;open_begin &amp;lt;= &amp;amp;open_end&amp;nbsp; %then %do;&lt;/P&gt;&lt;P&gt;&amp;amp;open_begin &amp;lt;= OPENDATE &amp;lt;= &amp;amp;open_end&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Sep 2018 09:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491814#M129082</guid>
      <dc:creator>wzca74</dc:creator>
      <dc:date>2018-09-01T09:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro conditions gave TRUE or FALSE on same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491817#M129085</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/229925"&gt;@wzca74&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, macro variables contain &lt;EM&gt;text&lt;/EM&gt;. (Nevertheless, integer arithmetic can be done: see "&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p17i177l3z4kzgn11m7pl8833ch7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;How the Macro Processor Evaluates Arithmetic Expressions&lt;/A&gt;".) In particular, your date literals ('01APR2017'd etc.) are in fact treated as character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, the first comparison ("top one") yields TRUE &lt;EM&gt;accidentally&lt;/EM&gt; because '&lt;STRONG&gt;0&lt;/STRONG&gt;... is alphabetically smaller than '&lt;STRONG&gt;3&lt;/STRONG&gt;... .&lt;/P&gt;
&lt;P&gt;The "bottom one" yields FALSE because '01&lt;STRONG&gt;A&lt;/STRONG&gt;... is&amp;nbsp;&lt;SPAN&gt;alphabetically &lt;EM&gt;not&lt;/EM&gt; greater than '01&lt;STRONG&gt;J&lt;/STRONG&gt;... (first inequality).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To make those comparisons work, use the &lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1d9ypna2tpt16n1xam57kuffcpt.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;%SYSEVALF&lt;/A&gt; function, e.g.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;... and &lt;STRONG&gt;%sysevalf(&lt;/STRONG&gt;&amp;amp;open_begin &amp;lt;= &amp;amp;open_end&lt;STRONG&gt;)&lt;/STRONG&gt; %then ...&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;And don't worry, you're not the first who had this problem:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/If-statement-using-dates/td-p/449095" target="_blank"&gt;%If statement using dates&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Sep 2018 11:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491817#M129085</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-01T11:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro conditions gave TRUE or FALSE on same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491818#M129086</link>
      <description>&lt;P&gt;The macro language is a&amp;nbsp;&lt;EM&gt;code generator&lt;/EM&gt;, which only knows the datatype text, and cannot do calculations on its own, with the exception of integer arithmetic in %if and %do. Therefore the date literals are treated as strings in comparisons.&lt;/P&gt;
&lt;P&gt;'01A is always "smaller" than '01J (in the collating sequence).&lt;/P&gt;
&lt;P&gt;If you follow Maxim 28 and use raw values in the macro variables&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let open_begin = %sysfunc(inputn(20170401,yymmdd8.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the comparisons will work as expected.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Sep 2018 11:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491818#M129086</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-01T11:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro conditions gave TRUE or FALSE on same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491829#M129096</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_self"&gt;FreelanceReinhard&lt;/A&gt;&amp;nbsp;for the detailed explanation. It is great!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Sep 2018 16:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491829#M129096</guid>
      <dc:creator>wzca74</dc:creator>
      <dc:date>2018-09-01T16:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro conditions gave TRUE or FALSE on same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491830#M129097</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;&lt;SPAN class="login-bold"&gt;KurtBremser&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;&amp;nbsp;for the answer. Appreciated!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Sep 2018 16:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-conditions-gave-TRUE-or-FALSE-on-same-values/m-p/491830#M129097</guid>
      <dc:creator>wzca74</dc:creator>
      <dc:date>2018-09-01T16:39:51Z</dc:date>
    </item>
  </channel>
</rss>

