<?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: Nesting macro definitions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451865#M114002</link>
    <description>&lt;P&gt;I'd NEVER do that. Use the autocall (or any SAS code) library in the usual way (1 macro -&amp;gt; 1 file). Just think of the nightmare of keeping such a convolution in a versioning system.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Apr 2018 13:29:44 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-04-06T13:29:44Z</dc:date>
    <item>
      <title>Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451733#M113938</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for an example where inner macro definition gets the input from outer macro definition.&amp;nbsp; Is this type of construction possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro outer;
   %global a
  
   %let a = 10;

	%macro inner;
		
		%if &amp;amp;a = 10 %then 
			%do;

		   .........

			%end;

	%mend inner;

%mend outer;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 00:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451733#M113938</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2018-04-06T00:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451736#M113939</link>
      <description>&lt;P&gt;Macros can pass information to one another without nesting their definitions&amp;nbsp; As a result, it is almost never good practice to nest macro definitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Almost never" allows for this possibility.&amp;nbsp; Should executing the %OUTER macro change the definition of the %INNER macro?&amp;nbsp; It's not a question of whether information can be passed.&amp;nbsp; That can always happen whether the definitions are nested or not.&amp;nbsp; It's a question of whether running %OUTER should change the meaning of %INNER.&amp;nbsp; That almost never happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 01:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451736#M113939</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-06T01:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451741#M113941</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404"&gt;@SAS_inquisitive&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for an example where inner macro definition gets the input from outer macro definition.&amp;nbsp; Is this type of construction possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Possible does not mean you should. And you really really shouldn't do this. Please never do this. Ever.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 01:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451741#M113941</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-06T01:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451745#M113942</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;. You got my point. I did not frame the question correctly. I meant to see how outer macro passes the information to the inner macro (not necessarily changing the meaning of inner macro).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is seemingly independent inner and outer macros. I want to see the correlation between them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro outer;
	%global a;
	%let a = 10;

	%macro inner;
		%global b;
		%let b = 20;
	%mend inner;

	%inner;
%mend;

%outer;
%put &amp;amp;a &amp;amp;b;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 02:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451745#M113942</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2018-04-06T02:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451761#M113949</link>
      <description>&lt;P&gt;Macros are NOT nested, the list of macro names is a simple list, not a heirarchy.&amp;nbsp; Nesting one macro's definition inside of another macro will not change that fact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro EXECUTION can be nested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If an outer macro calls an inner macro then the scope of the other macro is available to the running inner macro.&amp;nbsp; That means that macro variables defined as LOCAL in the outer macro exist and are visible to the inner macro to read and modify.&amp;nbsp; The exception is when the inner macro has its own LOCAL macro variable with the same name. The existence of that local macro variable will hide any macro variable(s) with the same name that exist in any currently running scope (including the GLOBAL scope).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you nest the macro definitions the only impact will be that every time you call the outer macro then the inner macro will be re-compiled (needlessly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot think of any way that you could change the definition of that inner macro by placing the definition inside the definition of the outer macro.&amp;nbsp; The only thing that I can think of that might have made it possible was a bug that impacted how macro variable references used in default values for parameters were handled.&amp;nbsp; But that was fixed.&amp;nbsp; Apparently the bug was introduced when they switched from PL/I to C compilers (early 80s?) and not fixed until just a few years ago.&amp;nbsp; Shows much that type of functionality was ever used/needed.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 04:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451761#M113949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T04:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451779#M113960</link>
      <description>&lt;P&gt;To keep my sanity, I have implemented this strategy for using macro variables in a macro:&lt;/P&gt;
&lt;P&gt;There are these four types of variables:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;macro variables that are actually parameters; these are by definition local&lt;/LI&gt;
&lt;LI&gt;existing global macro variables used for overall control of the code; these must not be changed inside the macro, have a fixed definition and are known by all developers (eg type of an external host from which files are read - UNIX/Mainframe/Windows); they are usually set at program start in autoexec or similar&lt;/LI&gt;
&lt;LI&gt;newly created variables for later global use, therefore appearing in a %global statement&lt;/LI&gt;
&lt;LI&gt;local macro variables, named in a %local statement; this encompasses all variables not in one of the above categories. %local prevents side-effects&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Other types of use are not allowed, to prevent unwanted side-effects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be certain exceptions, but these need to be clearly described in comments when made.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In light of this, the way you use &amp;amp;a in the "inner" macro is a violation of these principles and MUST NOT HAPPEN. Pass it as a parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as others have said, all %macro definitions are stored in the global symbol table, so trying to "nest" macro &lt;EM&gt;definitions&lt;/EM&gt; makes no sense. Nesting macro &lt;EM&gt;calls&lt;/EM&gt; is of course possible and requires caution and planning. You can even call macros recursively:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(x);
%put X=&amp;amp;x;
%if &amp;amp;x &amp;lt; 5
%then %do;
  %let x = %eval(&amp;amp;x+1);
  %test(&amp;amp;x);
%end;
%mend;

%test(1)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 07:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451779#M113960</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-06T07:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451825#M113983</link>
      <description>&lt;P&gt;It's easy enough to inspect the result.&amp;nbsp; The main point that I (and pretty much all) posters are making is that this gives you the same result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; outer&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token macrostatement"&gt;%global&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; a &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;10&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	&lt;SPAN class="token macroname"&gt;%inner&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; inner&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macrostatement"&gt;   %global&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macroname"&gt;   %let&lt;/SPAN&gt; b &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; inner&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token macroname"&gt;%outer&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrostatement"&gt;%put&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;a &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need to nest the definitions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 11:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451825#M113983</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-06T11:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451842#M113992</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use macro nesting to create libraries of macro functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance I have a file my_lib.sas containing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_lib;

  %macro mac1(x);
    ...
  %mend;

  %macro mac2(y,z);
    ...
  %mend;

...

%mend my_lib;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the file name (w.o. extension) has to be the same as the main macro name. That allows,&lt;/P&gt;
&lt;P&gt;in an external program, to get access to a family of macros with a simple macro call&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%my_lib&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mac1(10)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you consider it bad practice and if so, what would be the drawback ?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 12:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451842#M113992</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-06T12:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451847#M113993</link>
      <description>&lt;P&gt;Here are some factors to consider.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you set up the SASAUTOS option to identify where %MY_LIB is stored?&amp;nbsp; If you have, the other macros could also be made available without nesting by storing them in mac1.sas and mac2.sas.&amp;nbsp; (If you haven't done this, SASAUTOS is a good tool to examine.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nesting the macro definitions gives you long files, making it more difficult to decipher the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would %MAC1 and %MAC2 be valuable anywhere else, outside of %MY_LIB?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to locate where %MAC1 and %MAC2 are defined, wouldn't that be easier if there are files named mac1.sas and mac2.sas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do any other macros (other than %MY_LIB) imbed definitions of "convenient names" such as %MAC1 and %MAC2?&amp;nbsp; When you see %MAC1 or %MAC2 being used, do you know which version is being used?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Even if all these questions are easy for you to answer, would they be easy for someone else to answer as well?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 12:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451847#M113993</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-06T12:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451848#M113994</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use macro nesting to create libraries of macro functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance I have a file my_lib.sas containing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_lib;

  %macro mac1(x);
    ...
  %mend;

  %macro mac2(y,z);
    ...
  %mend;

...

%mend my_lib;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the file name (w.o. extension) has to be the same as the main macro name. That allows,&lt;/P&gt;
&lt;P&gt;in an external program, to get access to a family of macros with a simple macro call&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%my_lib&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mac1(10)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you consider it bad practice and if so, what would be the drawback ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How does that help? You get the same effect if you just&amp;nbsp;store all three definitions in the same source file without nesting them. When you %INCLUDE the file then all three are compiled.&amp;nbsp; And if you are using autocall macros then you could store all three definitions in the file named 'my_lib.sas' (without nesting them) and they will be defined the first time you call '%my_lib'.&amp;nbsp; SAS actually does this sometimes in the autocall library they provide.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still don't like having multiple macro definitions in the same file.&amp;nbsp;&amp;nbsp;What is to prevent someone from creating a different version of %MAC1 and storing it in another file?&amp;nbsp; Then you have a name conflict.&amp;nbsp; If you store all of your macro definitions in individual files (in the same directory) then the operating system will prevent name collisions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 12:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451848#M113994</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T12:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451854#M113995</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for your valuable input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea of grouping several macros in the same file is that they concern a common subject.&lt;/P&gt;
&lt;P&gt;We have a constraint that the directory structure that contains our programs is imposed by a&amp;nbsp; norm&lt;/P&gt;
&lt;P&gt;and we can not create sub directories to e.g. group macros by themes. As a result we have a small number&lt;/P&gt;
&lt;P&gt;of directories each containing many programs, so reducing the number of programs is a desirable goal.&lt;/P&gt;
&lt;P&gt;Those directories have indeed been declared in the SASAUTOS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the concern about macro names conflicts though it never occurred until now.&lt;/P&gt;
&lt;P&gt;We have a precise naming scheme that should avoid this kind of problems to occur&lt;/P&gt;
&lt;P&gt;but it is a good argument anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The use of a macro call instead of an include is just personal taste.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451854#M113995</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-06T13:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451856#M113996</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&amp;nbsp;And if you are using autocall macros then you could store all three definitions in the file named 'my_lib.sas' (without nesting them) and they will be defined the first time you call '%my_lib'.&amp;nbsp; &lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to check that because i think I already tried to do that and the compiler complained that the file contained no macro with the same name.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451856#M113996</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-06T13:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451859#M113998</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&amp;nbsp;And if you are using autocall macros then you could store all three definitions in the file named 'my_lib.sas' (without nesting them) and they will be defined the first time you call '%my_lib'.&amp;nbsp;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to check that because i think I already tried to do that and the compiler complained that the file contained no macro with the same name.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Definitely works as Tom described.&amp;nbsp; There should be one macro in the file where the macro name is the name of the file.&amp;nbsp; Other helper macros can be defined in the same file after that.&amp;nbsp; Even non-macro code can come after that and will be executed when the macro compiles.&amp;nbsp; Basically with an autocall library, SAS %includes the file with the macro definition the first time you call the macro.&amp;nbsp; There are risks of collisions as described.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451859#M113998</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-04-06T13:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451860#M113999</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&amp;nbsp;And if you are using autocall macros then you could store all three definitions in the file named 'my_lib.sas' (without nesting them) and they will be defined the first time you call '%my_lib'.&amp;nbsp;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have to check that because i think I already tried to do that and the compiler complained that the file contained no macro with the same name.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It definitely works. The autocall process will hunt for the filename corresponding to the unknown macro's name and sources the files contents and then proceeds to call the macro.&amp;nbsp; The error message you mentioned happens if the macro doesn't get defined. So if you saved your example into mac1.sas instead of my_lib.sas.&amp;nbsp; In that case just including the source wouldn't define mac1 since its definition was hidden inside of the definition of my_lib.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451860#M113999</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T13:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451865#M114002</link>
      <description>&lt;P&gt;I'd NEVER do that. Use the autocall (or any SAS code) library in the usual way (1 macro -&amp;gt; 1 file). Just think of the nightmare of keeping such a convolution in a versioning system.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451865#M114002</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-06T13:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451867#M114004</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for your valuable input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea of grouping several macros in the same file is that they concern a common subject.&lt;/P&gt;
&lt;P&gt;We have a constraint that the directory structure that contains our programs is imposed by a&amp;nbsp; norm&lt;/P&gt;
&lt;P&gt;and we can not create sub directories to e.g. group macros by themes. As a result we have a small number&lt;/P&gt;
&lt;P&gt;of directories each containing many programs, so reducing the number of programs is a desirable goal.&lt;/P&gt;
&lt;P&gt;Those directories have indeed been declared in the SASAUTOS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the concern about macro names conflicts though it never occurred until now.&lt;/P&gt;
&lt;P&gt;We have a precise naming scheme that should avoid this kind of problems to occur&lt;/P&gt;
&lt;P&gt;but it is a good argument anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The use of a macro call instead of an include is just personal taste.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In past we have imposed naming conventions that make it clear if a macro is just a helper macro for a main macro. For example by prefixing the name of the main macro.&amp;nbsp; So in your example you would have macros names %MYMAC, %MYMAC_MAC1, %MYMAC_MAC2 and the source could would be in files mymac.sas, mymac_mac1.sas, and mymac_mac2.sas&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451867#M114004</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T13:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451891#M114006</link>
      <description>&lt;P&gt;Sorry, I'm a bit slow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I, for instance, define a library for handling a users database, with three&lt;/P&gt;
&lt;P&gt;macros : %user_add, %user_del, %user_update. I can define the three macros in a&lt;/P&gt;
&lt;P&gt;file user_management.sas. AUTOCALL would not work because there is no macro&lt;/P&gt;
&lt;P&gt;%user_management.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I decide to rename my file user_add.sas, AUTOCALL would work but i would have to&lt;/P&gt;
&lt;P&gt;add a user prior to any other action which may be not what I want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could create an empty macro %user_management or ... use a nesting macro.&lt;/P&gt;
&lt;P&gt;The empty macro just seemed a bit strange to me hence the choice of nesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, I am not advocating any solution over another. I perfectly understand the recommandation&lt;/P&gt;
&lt;P&gt;of one macro per sas program. Grouping several macros in teh same program is just the workaround we&lt;/P&gt;
&lt;P&gt;found to organize our macros without the possibility of acting on the directory structure.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451891#M114006</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-06T14:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451898#M114007</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, I'm a bit slow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I, for instance, define a library for handling a users database, with three&lt;/P&gt;
&lt;P&gt;macros : %user_add, %user_del, %user_update. I can define the three macros in a&lt;/P&gt;
&lt;P&gt;file user_management.sas. AUTOCALL would not work because there is no macro&lt;/P&gt;
&lt;P&gt;%user_management.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I decide to rename my file user_add.sas, AUTOCALL would work but i would have to&lt;/P&gt;
&lt;P&gt;add a user prior to any other action which may be not what I want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could create an empty macro %user_management or ... use a nesting macro.&lt;/P&gt;
&lt;P&gt;The empty macro just seemed a bit strange to me hence the choice of nesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, I am not advocating any solution over another. I perfectly understand the recommandation&lt;/P&gt;
&lt;P&gt;of one macro per sas program. Grouping several macros in teh same program is just the workaround we&lt;/P&gt;
&lt;P&gt;found to organize our macros without the possibility of acting on the directory structure.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you are using autocall and your file is named user_management then it needs to have a macro definition in it for the macro %user_management.&amp;nbsp;If what it contains is the definition of other macros then every time you call it those macro will be re-defined, which is just a waste.&amp;nbsp; It also makes the file more confusing because there is an extra level of nesting you need worry about.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro user_management;
%put NOTE: You can now use the macros %str( %user_add, %user_del, and %user_update.);
%mend user_mangement;

%macro user_add

%mend user_add;

...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451898#M114007</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T14:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451912#M114008</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. I tested it out here. Thanks !&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro outer;
	%local a;
	%let a = 10;

	%macro inner;
		%let b = 10;
		%let total = %eval(&amp;amp;a + &amp;amp;b);
		%put &amp;amp;total;
	%mend inner;
	%inner;
%mend outer;
%outer;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451912#M114008</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2018-04-06T14:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting macro definitions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451925#M114012</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404"&gt;@SAS_inquisitive&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. I tested it out here. Thanks !&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro outer;
	%local a;
	%let a = 10;

	%macro inner;
		%let b = 10;
		%let total = %eval(&amp;amp;a + &amp;amp;b);
		%put &amp;amp;total;
	%mend inner;
	%inner;
%mend outer;
%outer;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You will get the same result without nesting the DEFINITIONS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inner;
  %let b = 10;
  %let total = %eval(&amp;amp;a + &amp;amp;b);
  %put &amp;amp;total;
%mend inner;
%macro outer;
  %local a;
  %let a = 10;
  %inner;
%mend outer;

%outer;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-macro-definitions/m-p/451925#M114012</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-06T14:54:19Z</dc:date>
    </item>
  </channel>
</rss>

