<?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: Why does null value of macro variable resolve as 0&amp;lt;&amp;var&amp;lt;1? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120730#M293528</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bravo for the correct answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Aug 2013 18:36:22 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2013-08-23T18:36:22Z</dc:date>
    <item>
      <title>Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120723#M293521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm perplexed by a situation I've encountered and I'm wondering if anyone can explain to me the inner SAS workings behind this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a list of macros variables that I am scrolling through and subjecting to macro conditional logic. Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let var1=0.1;&lt;/P&gt;&lt;P&gt;%let var2=0.5;&lt;/P&gt;&lt;P&gt;%let var3=1.5;&lt;/P&gt;&lt;P&gt;%let var4= ;&lt;/P&gt;&lt;P&gt;%let var5=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro q; &lt;/P&gt;&lt;P&gt;%if&amp;nbsp; 0 &amp;lt; &amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1 %then %put &amp;amp;&amp;amp;var&amp;amp;i is between 0 and 1;&lt;/P&gt;&lt;P&gt;%else %put &amp;amp;&amp;amp;var&amp;amp;i is not between 0 and 1; &lt;/P&gt;&lt;P&gt;%mend q;&lt;/P&gt;&lt;P&gt;%q&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is this: the macro variable that is null (in this case, &amp;amp;var4) seems to resolve this condition as TRUE! This seems strange to me! I understand that a null value of a macro variable is not the same as a missing value of a data step variable, but I'm still not sure why this should resolve as being 0&amp;lt;var&amp;lt;1. I have tried other conditions, such as %IF &amp;amp;&amp;amp;VAR&amp;amp;I &amp;gt; 1 and these do NOT resolve as TRUE. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have managed to get this code running fine using solutions to check for macro variables with null values prior to my conditional logic step, but my questions is WHY does &amp;amp;var4 resolve as being between 0 and 1? Can anyone explain to me the SAS workings behind this? Like I said, the code is working find with some work-arounds, but I am curious to know the reason behind it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any insight you can provide!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ashley&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 16:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120723#M293521</guid>
      <dc:creator>ashlicole</dc:creator>
      <dc:date>2013-08-23T16:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120724#M293522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This&lt;/P&gt;&lt;P&gt;0 &amp;lt; &amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1&lt;/P&gt;&lt;P&gt;type of logic doesn't work in macro world, you need to specify it as &lt;STRONG&gt;0 &amp;lt; &amp;amp;&amp;amp;var&amp;amp;i&amp;nbsp; and &amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;There's an explanation of why somewhere on here but I don't recall &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;I think it resolves as 0&amp;lt;null = false then false&amp;lt;1 which is true rather than as vari between 0 and 1.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 16:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120724#M293522</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-08-23T16:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120725#M293523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be careful when to use "0 &amp;lt; &amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1 ", in Macro, it will be interpreted as 0 &amp;lt; (&amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1). So anything that is less then 1 will be true, including those negative numbers.&amp;nbsp; Instead, breaking it up seems to be the safer way:&lt;/P&gt;&lt;P&gt; &amp;amp;&amp;amp;var&amp;amp;i&amp;nbsp; &amp;gt;0 and &amp;amp;&amp;amp;var&amp;amp;i &amp;lt; 1&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 16:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120725#M293523</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-08-23T16:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120726#M293524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From the looks of those macro variable decimal values, I'm thinking you need to get %SYSEVALF involved.&amp;nbsp; Or better still don't use macro for this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 17:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120726#M293524</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-08-23T17:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120727#M293525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Absolutely. &lt;/P&gt;&lt;P&gt;"You must use the %SYSEVALF function to evaluate logical expressions containing floating-point or missing values."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001072297.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001072297.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120727#M293525</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-08-23T18:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120728#M293526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do something as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;format x 9.3 y $4. z $50.;&lt;/P&gt;&lt;P&gt;do i=1 to 5 ;&lt;/P&gt;&lt;P&gt; x = symget('var'||left(i));&lt;/P&gt;&lt;P&gt; y = 'var'||left(i);&lt;/P&gt;&lt;P&gt; if ( 0 &amp;lt; x &amp;lt; 1 ) then do ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = y || " is between 0 and 1";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put z;&lt;/P&gt;&lt;P&gt; end ;&lt;/P&gt;&lt;P&gt; else do ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; z = y || " is not between 0 and 1";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put z; &lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; output;&lt;/P&gt;&lt;P&gt;end ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120728#M293526</guid>
      <dc:creator>Fugue</dc:creator>
      <dc:date>2013-08-23T18:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120729#M293527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ashley,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two issues you will run into.&amp;nbsp; The first one explains the results for &amp;amp;VAR4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;a &amp;lt; &amp;amp;b &amp;lt; &amp;amp; c %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In macro language, expressions resolve from left to right.&amp;nbsp; This statement operates as if you had added parentheses:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if (&amp;amp;a &amp;lt; &amp;amp;b) &amp;lt; &amp;amp;c %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Macro makes the first comparison, and replaces true comparisons with 1 and false comparisons with 0.&amp;nbsp; In your case, when &amp;amp;VAR4 is null, null is less then 0 so the first comparison is false.&amp;nbsp; The second comparison then becomes:&amp;nbsp; 0 &amp;lt; 1 which is, of course, true. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second issue you will encounter has to do with decimal points.&amp;nbsp; When macro language makes comparisons, it applies the %EVAL function.&amp;nbsp; %EVAL interprets decimal points as character strings.&amp;nbsp; Thus this comparison would also be true:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if 39 &amp;lt; 4.0 %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As others have noted, %SYSEVALF can perform decimal fraction arithmatic.&amp;nbsp; This comparison would be false:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if %sysevalf (39 &amp;lt; 4.0) %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120729#M293527</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-08-23T18:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120730#M293528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bravo for the correct answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120730#M293528</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-08-23T18:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why does null value of macro variable resolve as 0&lt;&amp;var&lt;1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120731#M293529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Astounding, for putting this so eloquently! The left-to-right logic makes perfect sense to me and i can now see the problem with this comparison!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. thanks to all for the %SYSEVALF tip as well... i had actually sort of simplified/anonymized my code to post this question and hence the code i listed would not actually have worked without %SYSEVALF, but my real code was fine (other than that darn null macro variable!). thank you regardless for the feedback on that too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Aug 2013 18:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-null-value-of-macro-variable-resolve-as-0-lt-var-lt-1/m-p/120731#M293529</guid>
      <dc:creator>ashlicole</dc:creator>
      <dc:date>2013-08-23T18:43:31Z</dc:date>
    </item>
  </channel>
</rss>

