<?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: Exit macro within loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139810#M28198</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This statement:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%if dept&amp;lt;10&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;instructs the macro compiler to compare the character string &lt;STRONG&gt;dept&lt;/STRONG&gt; with the number &lt;STRONG&gt;10&lt;/STRONG&gt;.&amp;nbsp; This is why you got the message "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;A character operand was found ... where a numeric operand is required."&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Is there any need to use macro language at all? The data step can probably do everything you need.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Jul 2014 05:19:53 GMT</pubDate>
    <dc:creator>dkb</dc:creator>
    <dc:date>2014-07-29T05:19:53Z</dc:date>
    <item>
      <title>Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139809#M28197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am now doing the school payment project and preparing a SAS program to handle this.&amp;nbsp; As I want to filter out the observations from the dataset by a looping step with some conditional criteria in the following program, and syntax errors are found in the SAS log.&amp;nbsp; I have tried to omit the macro and the program work smoothly.&amp;nbsp; Please help to give me some hints to tackle this as I wish to exit the macro iteration if certain criteria match.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*************************************************************************&lt;/P&gt;&lt;P&gt;/* Dummy data.&amp;nbsp; Exit the macro if certain criteria match. */;&lt;BR /&gt;data output.test;&lt;BR /&gt;&amp;nbsp; input staff dept payment;&lt;BR /&gt;&amp;nbsp; datalines;&lt;BR /&gt;1 10&amp;nbsp;&amp;nbsp; 123456.123&lt;BR /&gt;2 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13123.123&lt;BR /&gt;3&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60001.123&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let num=100;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;BR /&gt;&amp;nbsp; %do x=1 %to &amp;amp;num;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let digit=10000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if dept&amp;lt;10 and round(payment,&amp;amp;digit)&amp;gt;=50000 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put staff= dept= paymnet=;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;%mend loop;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;BR /&gt;&amp;nbsp; set output.test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %loop;&lt;BR /&gt;run;&lt;BR /&gt;*************************************************************************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOG&lt;BR /&gt;--------------------------------------&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; data test;&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input staff dept payment;&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.TEST has 3 observations and 3 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;9&lt;BR /&gt;10&amp;nbsp;&amp;nbsp; %let num=100;&lt;BR /&gt;11&lt;BR /&gt;12&amp;nbsp;&amp;nbsp; %macro loop;&lt;BR /&gt;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do x=1 %to &amp;amp;num;&lt;BR /&gt;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let digit=10000;&lt;BR /&gt;15&lt;BR /&gt;16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if dept&amp;lt;10 and round(payment,&amp;amp;digit)&amp;gt;=50000 %then %do;&lt;BR /&gt;17&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put staff= dept= paymnet=;&lt;BR /&gt;18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %return;&lt;BR /&gt;19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;21&amp;nbsp;&amp;nbsp; %mend loop;&lt;BR /&gt;22&lt;BR /&gt;23&amp;nbsp;&amp;nbsp; data _NULL_;&lt;BR /&gt;24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;BR /&gt;25&lt;BR /&gt;26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %loop;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: dept&amp;lt;10 and round(payment,&amp;amp;digit)&amp;gt;=50000&lt;BR /&gt;ERROR: The macro LOOP will stop executing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;may&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 03:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139809#M28197</guid>
      <dc:creator>wongmay</dc:creator>
      <dc:date>2014-07-29T03:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139810#M28198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This statement:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%if dept&amp;lt;10&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;instructs the macro compiler to compare the character string &lt;STRONG&gt;dept&lt;/STRONG&gt; with the number &lt;STRONG&gt;10&lt;/STRONG&gt;.&amp;nbsp; This is why you got the message "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;A character operand was found ... where a numeric operand is required."&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Is there any need to use macro language at all? The data step can probably do everything you need.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 05:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139810#M28198</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2014-07-29T05:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139811#M28199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually in the dataset created, the DEPT is a numeric variable so I compare it with number 10.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me explain clearer what I want to do from the program.&amp;nbsp; The program will involve some procedure steps (not yet written above) which will be converged to certain value of payment during multiple iterations of loops.&amp;nbsp; So, I want to stop the macro and print the result once it is found, instead of executing maximun no. of macro loops, say 100.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for misleading readers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 05:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139811#M28199</guid>
      <dc:creator>wongmay</dc:creator>
      <dc:date>2014-07-29T05:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139812#M28200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;.. but you don't need the macro. If you replace the data _NULL_ with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _NULL_;&lt;BR /&gt;&amp;nbsp; set test;&lt;BR /&gt;&amp;nbsp; Do x=1 To &amp;amp;num.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Let digit=10000;&lt;BR /&gt; If dept &amp;lt; 10 and round (payment,&amp;amp;digit.)&amp;gt;=50000 Then Do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Put Staff= Dept= Payment=;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Return;&lt;BR /&gt; End;&lt;BR /&gt;&amp;nbsp; End;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 05:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139812#M28200</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-07-29T05:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139813#M28201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with user24feb, a macro is not needed here.&amp;nbsp; I would suggest not creating global macros in code however as its not clear to read.&amp;nbsp; One other to mention, if you have to use macros, and as this is a learning exercise you may need to, then have a look at this paper: &lt;A href="http://www2.sas.com/proceedings/forum2007/067-2007.pdf" title="http://www2.sas.com/proceedings/forum2007/067-2007.pdf"&gt;http://www2.sas.com/proceedings/forum2007/067-2007.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;which details all the different loop constructs, including the %do %while, which has the ability to loop until certain criteria are reached.&amp;nbsp; So instead of the do I=x to y, you could use a do loop as:&lt;/P&gt;&lt;P&gt;%let I=1;&lt;/P&gt;&lt;P&gt;%do&amp;nbsp; %while (&amp;amp;I &amp;lt;= 1000 and -your conditions to stop here-);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 08:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139813#M28201</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-07-29T08:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139814#M28202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many thanks to all of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;may&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 09:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139814#M28202</guid>
      <dc:creator>wongmay</dc:creator>
      <dc:date>2014-07-29T09:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139815#M28203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Actually in the dataset created, the DEPT is a numeric variable so I compare it with number 10.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;That's a data step variable, not a macro variable; they are not the same thing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;But even if you do have a macro variable called DEPT that has a numeric value, your code &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%if dept&amp;lt;10&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;still fails for the reason I gave above; you need to instruct the macro compiler to resolve the variable by coding&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; &lt;STRONG&gt;%if &amp;amp;DEPT &amp;lt; 10&lt;/STRONG&gt; .&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 23:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139815#M28203</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2014-07-29T23:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Exit macro within loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139816#M28204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Many thanks to all of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;may&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 00:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exit-macro-within-loop/m-p/139816#M28204</guid>
      <dc:creator>wongmay</dc:creator>
      <dc:date>2014-08-01T00:10:22Z</dc:date>
    </item>
  </channel>
</rss>

