<?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: Nested macros variables usage in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626996#M184998</link>
    <description>&lt;P&gt;Nesting macros is a bad idea.&amp;nbsp;&lt;BR /&gt;Separate them out into their own definition and then call the other macro if needed, but there should never be a need to nest like this and I would highly recommend against it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286929"&gt;@eduard1231&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am planning to create following macro structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro macro1(x,y,z)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;%macro macro2(a,b,c)&lt;BR /&gt;.&lt;BR /&gt;some manipulation with x,y,z here&lt;BR /&gt;.&lt;BR /&gt;%mend macro2&lt;BR /&gt;%mend macro1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will this work? I am worried for x y z manipulation in macro2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2020 19:52:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-24T19:52:16Z</dc:date>
    <item>
      <title>Nested macros variables usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626989#M184993</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am planning to create following macro structure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro macro1(x,y,z)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;%macro macro2(a,b,c)&lt;BR /&gt;.&lt;BR /&gt;some manipulation with x,y,z here&lt;BR /&gt;.&lt;BR /&gt;%mend macro2&lt;BR /&gt;%mend macro1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will this work? I am worried for x y z manipulation in macro2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 19:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626989#M184993</guid>
      <dc:creator>eduard1231</dc:creator>
      <dc:date>2020-02-24T19:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macros variables usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626993#M184996</link>
      <description>&lt;P&gt;Preferred and highly recommended is to not nest the macros&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro macro1(x,y,z)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;%mend macro1;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;%macro macro2(a,b,c)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;some manipulation with x,y,z here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%mend macro2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, it's not really clear to me what your concern is. It's also not clear to me how or when or where in the code you are calling these two macros.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 19:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626993#M184996</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-24T19:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macros variables usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626996#M184998</link>
      <description>&lt;P&gt;Nesting macros is a bad idea.&amp;nbsp;&lt;BR /&gt;Separate them out into their own definition and then call the other macro if needed, but there should never be a need to nest like this and I would highly recommend against it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286929"&gt;@eduard1231&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am planning to create following macro structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro macro1(x,y,z)&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;%macro macro2(a,b,c)&lt;BR /&gt;.&lt;BR /&gt;some manipulation with x,y,z here&lt;BR /&gt;.&lt;BR /&gt;%mend macro2&lt;BR /&gt;%mend macro1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will this work? I am worried for x y z manipulation in macro2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 19:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/626996#M184998</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-24T19:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macros variables usage</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/627002#M185001</link>
      <description>&lt;P&gt;First of all the name space for macros is flat.&amp;nbsp; You cannot actually nest macro definitions. There can only be one macro named MACRO2 at any point in time.&amp;nbsp; So it will just confuse you if you structure your source code to have one macro defined inside of another macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you are actually worried about the possibility of the &lt;STRONG&gt;execution&lt;/STRONG&gt; of macro2 when called by macro1 making changes to the local macro variables in macro1.&amp;nbsp; There is &lt;STRONG&gt;nothing&lt;/STRONG&gt; that MACRO1 can do to prevent this.&amp;nbsp; It is up to macro2 to not modify macro variables it does not intend to modify.&amp;nbsp; In your example if MACRO2 wants to use macro variable name X then it should take care to define it as LOCAL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro macro1(x,y,z);
...
%macro2;
...
%mend macro1;

%macro macro2(a,b,c);
%local x ;
%do x=1 %to &amp;amp;a ;
  ...
%end;
%mend macro2;

%macro1(2,3,4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 20:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macros-variables-usage/m-p/627002#M185001</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-24T20:07:46Z</dc:date>
    </item>
  </channel>
</rss>

