<?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: Not able to resolve macro within %do loop. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125327#M25595</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Harish,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my take on what happened.&amp;nbsp; First, on your diagnosis, we can't see the messages you got and I would reserve the right to change my mind if I saw them.&amp;nbsp; I don't believe that &amp;amp;B couldn't be resolved the first time (unless you have messages to the contrary).&amp;nbsp; Rather, here's what I suspect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you define the macro like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro report();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS allows that there might be parameters entered. Invoking the macro like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%report&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;isn't enough to trigger the macro to execute.&amp;nbsp; SAS waits, thinking that you might still enter parameters in parentheses.&amp;nbsp; That's the result after one iteration through the %DO loop.&amp;nbsp; Then the %DO loop continues with &amp;amp;i=2, resetting &amp;amp;B and redefining %REPORT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, SAS encounters the second invocation of %REPORT.&amp;nbsp; That's enough for SAS to recognize that the first invocation is complete, and no parameters will be forthcoming.&amp;nbsp; So the first time %REPORT actually executes is at the end of the second iteration of the %DO loop, when &amp;amp;B has already been changed to BAS.&amp;nbsp; And the second execution of %REPORT hangs (or eventually runs with &amp;amp;B again equal to BAS), awaiting either parameters or some other trigger that tells SAS that there won't be any parameters.&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>Thu, 24 May 2012 18:59:37 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2012-05-24T18:59:37Z</dc:date>
    <item>
      <title>Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125322#M25590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me where i am going wrong? I tried to rectify the mistake but i am not able to do so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options symbolgen mlogic;&lt;/P&gt;&lt;P&gt;%macro scp;&lt;/P&gt;&lt;P&gt;%global lob1 lob2 b;&lt;/P&gt;&lt;P&gt;%let lob1 = XAB;&lt;/P&gt;&lt;P&gt;%let lob2 = BAS;&lt;/P&gt;&lt;P&gt;%do l = 1 %to 2;&lt;/P&gt;&lt;P&gt;%let b = &amp;amp;&amp;amp;lob&amp;amp;l;&lt;/P&gt;&lt;P&gt;%macro report();&lt;/P&gt;&lt;P&gt;ods listing close;&lt;/P&gt;&lt;P&gt;ods html file = "/rpt6_&amp;amp;b_..xls";&lt;/P&gt;&lt;P&gt;data empty4;&lt;/P&gt;&lt;P&gt;msg = "welcome";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend report;&lt;/P&gt;&lt;P&gt;%report&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend scp;&lt;/P&gt;&lt;P&gt;%scp&lt;/P&gt;&lt;P&gt;Not able to resolve macro variable b for the first iteration and for the second iteration it is showing the value of lob2 which is BAS. I sahould have value XAB for first iteration and BAS for second iteration and i am not able to resolve macro variable b for the first iteration. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Harish.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2012 02:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125322#M25590</guid>
      <dc:creator>hari1109</dc:creator>
      <dc:date>2012-05-24T02:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125323#M25591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Got solved but i don't know the reason :&lt;/P&gt;&lt;P&gt;Changed %macro report(); to %macro report; and it worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Harish.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2012 02:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125323#M25591</guid>
      <dc:creator>hari1109</dc:creator>
      <dc:date>2012-05-24T02:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125324#M25592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are defining the macro variable B and referencing the macro variable B_.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Did you mean to use rpt6_&amp;amp;b._.xls as the filename?&amp;nbsp; &lt;/P&gt;&lt;P&gt;Do you really want the extra underscore?&lt;/P&gt;&lt;P&gt;Also do you really want to write to the root directory of your file system by starting the filename with a slash?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2012 03:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125324#M25592</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-05-24T03:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125325#M25593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see any reason to define the REPORT macro within the SCP macro. You would probably be better off making in a separate definition with parameters and then calling the Report macro in the loop with &amp;amp;b as a parameter;&lt;/P&gt;&lt;P&gt;You need to provide for a close of your HTML file and reopen the listing destination;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect you have trimmed a lot of your code out as the example wouldn't create any output.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2012 14:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125325#M25593</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-05-24T14:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125326#M25594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom / ballarw,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No i don't need the extra underscore , yes&amp;nbsp; i would like to use it as a filename and no, i didn't included the entire file path sorry for that. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes ballardw , sure i will do that and yes i trimmed a lot but i am getting the output with original code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Harish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 May 2012 15:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125326#M25594</guid>
      <dc:creator>hari1109</dc:creator>
      <dc:date>2012-05-24T15:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to resolve macro within %do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125327#M25595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Harish,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my take on what happened.&amp;nbsp; First, on your diagnosis, we can't see the messages you got and I would reserve the right to change my mind if I saw them.&amp;nbsp; I don't believe that &amp;amp;B couldn't be resolved the first time (unless you have messages to the contrary).&amp;nbsp; Rather, here's what I suspect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you define the macro like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro report();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS allows that there might be parameters entered. Invoking the macro like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%report&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;isn't enough to trigger the macro to execute.&amp;nbsp; SAS waits, thinking that you might still enter parameters in parentheses.&amp;nbsp; That's the result after one iteration through the %DO loop.&amp;nbsp; Then the %DO loop continues with &amp;amp;i=2, resetting &amp;amp;B and redefining %REPORT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, SAS encounters the second invocation of %REPORT.&amp;nbsp; That's enough for SAS to recognize that the first invocation is complete, and no parameters will be forthcoming.&amp;nbsp; So the first time %REPORT actually executes is at the end of the second iteration of the %DO loop, when &amp;amp;B has already been changed to BAS.&amp;nbsp; And the second execution of %REPORT hangs (or eventually runs with &amp;amp;B again equal to BAS), awaiting either parameters or some other trigger that tells SAS that there won't be any parameters.&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>Thu, 24 May 2012 18:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-able-to-resolve-macro-within-do-loop/m-p/125327#M25595</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-24T18:59:37Z</dc:date>
    </item>
  </channel>
</rss>

