<?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: use of %eval in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113646#M31473</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would flip that around.&amp;nbsp; I wouldn't worry about the automatic insertion of %EVAL() but instead remember to think of macro code as generating strings. In particular in your example the problem was in your %LET statement and not in the %UNTIL() clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also remember that if you want to evaluate floating point arithmetic in macro world you will need to use the %SYSEVALF() function.&amp;nbsp; %EVAL() only does integer arithmetic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general macro code is not a good place to perform mathematical operations, in general you should arrange your code so that such activity is happening in PROC's and DATA steps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Nov 2012 11:50:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-11-01T11:50:41Z</dc:date>
    <item>
      <title>use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113639#M31466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please look at the code below - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro testeval;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let cnt = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do until(&amp;amp;cnt =5);&lt;/P&gt;&lt;P&gt;%let cnt = &amp;amp;cnt + 1;&lt;/P&gt;&lt;P&gt;%put cnt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;has the following output:&lt;/P&gt;&lt;P&gt;0 + 1&lt;/P&gt;&lt;P&gt;0 + 1 + 1&lt;/P&gt;&lt;P&gt;0 + 1 + 1 + 1&lt;/P&gt;&lt;P&gt;0 + 1 + 1 + 1 + 1&lt;/P&gt;&lt;P&gt;0 + 1 + 1 + 1 + 1 + 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The loop goes till 5 iterations which means the integral sum is being calculated and the value of cnt is 5 as understood by the SAS system, however, as an output the values of cnt are not 1,2,3,4,5.&lt;/P&gt;&lt;P&gt;If we use %eval(&amp;amp;cnt + 1), we can have those values of cnt but still, the SAS system executes the loop 5 times..Then why doesn't it output those values..or does this mean that we can perform logical and arithmetic operations on macro variables (integral values) without the use of %eval but can get their true values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please enlighten!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 18:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113639#M31466</guid>
      <dc:creator>varunnakra</dc:creator>
      <dc:date>2012-10-31T18:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113640#M31467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;varunnakra,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;Perhaps this will help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;When a macro variable is logically compared to a constant integer, such as your until clause (&amp;amp;cnt =5), the macro compiller does an explicit %eval for the comparison.&amp;nbsp; So 0 +1 is not equal to 5 but 0 + 1 +1 +1 +1 +1 is equal to 5.&amp;nbsp; This does not change the internal value of cnt which is always something like 0, 0 +1, 0 +1 +1, etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;try adding %eval in your let statement -- %let cnt = %eval(&amp;amp;cnt + 1) ;&amp;nbsp; That will explicitly do the integer arithmetic.&amp;nbsp; In your original case, you are just appending the string ' + 1' to the previous string value of cnt.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="replyToName"&gt;Larry&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 18:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113640#M31467</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2012-10-31T18:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113641#M31468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are some cases where you can perform arithmetic on macro variables without specifying %eval.&amp;nbsp; Macro language does it for you.&amp;nbsp; For example, if a mathematical operator appears in a %IF condition, macro language attempts to perform the math.&amp;nbsp; So this group of statements finds a Match:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let a = 5;&lt;/P&gt;&lt;P&gt;%let b = 3 + 2;&lt;/P&gt;&lt;P&gt;%put &amp;amp;a &amp;amp;b;&lt;/P&gt;&lt;P&gt;%if &amp;amp;a = &amp;amp;b %then %put Match;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There are other places where %EVAL is assumed to be needed, such as here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This automatic invocation of %EVAL is not always your friend.&amp;nbsp; The first statement below is perfectly legal, but the second always generates an error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let rank = A-1;&lt;/P&gt;&lt;P&gt;%if &amp;amp;rank = A-1 %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The %IF statement sees subtraction, and attempts to perform math on A-1.&amp;nbsp; There are ways around this, but the answer to your original question is that macro language has situations where it decides to apply the %EVAL function for you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 20:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113641#M31468</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-10-31T20:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113642#M31469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have both variables cnt and &amp;amp;cnt, did you mean to do that. I find that can confuse me fast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie %put cnt should be %put &amp;amp;cnt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And you need a % before the until.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following works fine for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro testeval;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let cnt = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do %until (&amp;amp;cnt=5);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let cnt = %eval(&amp;amp;cnt + 1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;cnt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%testeval;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 20:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113642#M31469</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-10-31T20:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113643#M31470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you have a test in macro code then SAS does an implied %EVAL().&amp;nbsp; This is true for %IF and %DO conditions.&lt;/P&gt;&lt;P&gt;So it is as if you coded :&lt;/P&gt;&lt;P&gt;%do %until ( %eval(&amp;amp;cnt = 5) ) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is why the string "0 + 1 + 1 + 1 + 1 + 1" that you are generating into your macro variable CNT caused the %DO loop to stop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 02:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113643#M31470</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-11-01T02:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113644#M31471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes, i am sorry to have missed on the %'s and the &amp;amp;'s.. I was writing this code here feeling a little dizzy..&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 04:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113644#M31471</guid>
      <dc:creator>varunnakra</dc:creator>
      <dc:date>2012-11-01T04:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113645#M31472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Conclusively, one must use %eval in logical or arithmetic operations just to be sure that there is not an error when SAS doesnt perform an automatic conversion..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 05:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113645#M31472</guid>
      <dc:creator>varunnakra</dc:creator>
      <dc:date>2012-11-01T05:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: use of %eval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113646#M31473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would flip that around.&amp;nbsp; I wouldn't worry about the automatic insertion of %EVAL() but instead remember to think of macro code as generating strings. In particular in your example the problem was in your %LET statement and not in the %UNTIL() clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also remember that if you want to evaluate floating point arithmetic in macro world you will need to use the %SYSEVALF() function.&amp;nbsp; %EVAL() only does integer arithmetic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general macro code is not a good place to perform mathematical operations, in general you should arrange your code so that such activity is happening in PROC's and DATA steps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 11:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/use-of-eval/m-p/113646#M31473</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-11-01T11:50:41Z</dc:date>
    </item>
  </channel>
</rss>

