<?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 Do Loop Within a Do Loop and Macro inside of that - Not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590647#M169094</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have Do Loop within a Do Loop and Macro's inside of that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the Sequence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone please help on this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO My_Macro_1;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 2; &amp;lt;---this loop only execute 1st time, but, does not calling 2nd time - that's the issue and questions&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;One_Variable&lt;BR /&gt;from Table1;&lt;BR /&gt;Quit;&lt;BR /&gt;%My_Macro_2(&amp;amp;Para1.);&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;Select&lt;BR /&gt;.....&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;%MACRO My_Macro_3;&lt;BR /&gt;%do i = 1 %to 47; &amp;lt;---this loop execute 47 times, when i = 1 for outer loop, but, does not calling 2nd time - that's the issue and questions&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;Quit;&lt;BR /&gt;%My_Macro_4(&amp;amp;Para2.);&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND My_Macro_3;&lt;BR /&gt;%My_Macro_3;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND My_Macro_1;&lt;BR /&gt;%My_Macro_1;&lt;/P&gt;</description>
    <pubDate>Sat, 21 Sep 2019 19:33:56 GMT</pubDate>
    <dc:creator>NilNidhiEva</dc:creator>
    <dc:date>2019-09-21T19:33:56Z</dc:date>
    <item>
      <title>Do Loop Within a Do Loop and Macro inside of that - Not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590647#M169094</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have Do Loop within a Do Loop and Macro's inside of that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the Sequence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone please help on this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO My_Macro_1;&lt;/P&gt;&lt;P&gt;%do i = 1 %to 2; &amp;lt;---this loop only execute 1st time, but, does not calling 2nd time - that's the issue and questions&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;One_Variable&lt;BR /&gt;from Table1;&lt;BR /&gt;Quit;&lt;BR /&gt;%My_Macro_2(&amp;amp;Para1.);&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;Select&lt;BR /&gt;.....&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;%MACRO My_Macro_3;&lt;BR /&gt;%do i = 1 %to 47; &amp;lt;---this loop execute 47 times, when i = 1 for outer loop, but, does not calling 2nd time - that's the issue and questions&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;.....&lt;BR /&gt;.....&lt;BR /&gt;Quit;&lt;BR /&gt;%My_Macro_4(&amp;amp;Para2.);&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND My_Macro_3;&lt;BR /&gt;%My_Macro_3;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%MEND My_Macro_1;&lt;BR /&gt;%My_Macro_1;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 19:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590647#M169094</guid>
      <dc:creator>NilNidhiEva</dc:creator>
      <dc:date>2019-09-21T19:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Within a Do Loop and Macro inside of that - Not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590648#M169095</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would say 3 words: macro variables scoping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try to add;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local i;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;inside macro3 and macro2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Somme additional reading:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1b76sxg9dbcyrn1l5age5j5nvgw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1b76sxg9dbcyrn1l5age5j5nvgw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sgf/2015/02/13/sas-macro-variables-how-to-determine-scope/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2015/02/13/sas-macro-variables-how-to-determine-scope/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 19:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590648#M169095</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-21T19:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Within a Do Loop and Macro inside of that - Not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590697#M169112</link>
      <description>&lt;P&gt;You are just making the code more confusing by placing macro definitions inside of each other.&amp;nbsp; There is just a single name space for macros.&amp;nbsp; But every macro does create its own name space (scope) for macro variables.&amp;nbsp; If you don't define a macro variable as LOCAL to the macro and there already exists a macro variable in an outer scope then it will be used.&amp;nbsp; So when control returns from macro three the value of I is now larger than the upper limit of the do loop in the macro one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO My_Macro_3;
%local i;
%do i = 1 %to 47;
  .....
%end;
%MEND My_Macro_3;


%MACRO My_Macro_1;
%local i;
%do i = 1 %to 2;
  ...&lt;BR /&gt;  %My_Macro_2(&amp;amp;Para1.);
  .....
  %My_Macro_3;
%end;
%MEND My_Macro_1;

%My_Macro_1;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Sep 2019 04:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Within-a-Do-Loop-and-Macro-inside-of-that-Not-working/m-p/590697#M169112</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-22T04:13:19Z</dc:date>
    </item>
  </channel>
</rss>

