<?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: SAS global macro vs local macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967431#M376364</link>
    <description>Thanks for all your patients and reply, kindly elaborate below points , great help for me.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%let a=20;&lt;BR /&gt;&lt;BR /&gt;%macro check;&lt;BR /&gt;%let a=50;&lt;BR /&gt;%put inside &amp;amp;a.;&lt;BR /&gt;%mend check;&lt;BR /&gt;%check;&lt;BR /&gt;&lt;BR /&gt;%put outside &amp;amp;a.;&lt;BR /&gt;&lt;BR /&gt;1. so, if there is a macro variable already defined as global, it will be global until we mentioned as local ?&lt;BR /&gt;2. macro parameters are by default, local variables ?&lt;BR /&gt;3.Macros will be stored in different two tables right ?, then it can store separately, a=20 as global because i have derived it with open code let statement and can store a=50 in local table can be referred only during that particular macro. ?&lt;BR /&gt;4. how this storing process works in SAS for macro variables ?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Pavan.&lt;BR /&gt;</description>
    <pubDate>Sun, 25 May 2025 17:37:35 GMT</pubDate>
    <dc:creator>narravulap</dc:creator>
    <dc:date>2025-05-25T17:37:35Z</dc:date>
    <item>
      <title>SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49972#M10421</link>
      <description>56. The following SAS program is submitted:&lt;BR /&gt;
%let a=cat;&lt;BR /&gt;
%macro animal(a=frog);&lt;BR /&gt;
   %let a=bird;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%animal(a=pig)&lt;BR /&gt;
%put a is &amp;amp;a;&lt;BR /&gt;
Which one of the following is written to the SAS log?&lt;BR /&gt;
(A) a is &amp;amp;a&lt;BR /&gt;
(B) a is cat&lt;BR /&gt;
(C) a is pig&lt;BR /&gt;
(D) a is bird&lt;BR /&gt;
&lt;BR /&gt;
The answer is B. But why (D) is not correct? Thanks a lot!</description>
      <pubDate>Wed, 13 Apr 2011 20:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49972#M10421</guid>
      <dc:creator>richard_hu2003</dc:creator>
      <dc:date>2011-04-13T20:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49973#M10422</link>
      <description>Hello Richard_hu2003,&lt;BR /&gt;
&lt;BR /&gt;
The question is related to global and local macrovariables relationship. In this case we have a global macro variable a with value 'cat', and inside the macro we have a local macrovariable a with value 'bird'. These are two different macro variables. Because macro does not change global macro variable its value remains unchanged and equals to 'cat'.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 13 Apr 2011 20:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49973#M10422</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-13T20:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49974#M10423</link>
      <description>Got it! Thanks!</description>
      <pubDate>Wed, 13 Apr 2011 21:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49974#M10423</guid>
      <dc:creator>richard_hu2003</dc:creator>
      <dc:date>2011-04-13T21:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49975#M10424</link>
      <description>Richard_hu2003,&lt;BR /&gt;
&lt;BR /&gt;
SPR is absolutly correct but the reason that there is a local and global version of &amp;amp;A is more subtle.  A slight change in the program will give D as the answer.&lt;BR /&gt;
[pre]%let a=cat;&lt;BR /&gt;
%macro animal(b=frog);&lt;BR /&gt;
%let a=bird;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%animal(b=pig)&lt;BR /&gt;
%put a is &amp;amp;a;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
now there is no version of &amp;amp;A on the local table,  and cat is replaced by bird.  &lt;BR /&gt;
&lt;BR /&gt;
In your original version of the macro %ANIMAL it is the parameter (A=) that forces a &amp;amp;A to appear on the local table.  A %LET inside the macro is not sufficient.  I feel that this is an important, albeit fairly subtle, difference in behavior that gets folks into trouble.</description>
      <pubDate>Mon, 25 Apr 2011 05:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49975#M10424</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-04-25T05:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49976#M10425</link>
      <description>Very helpful!! Thanks, ArtC.</description>
      <pubDate>Mon, 25 Apr 2011 14:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/49976#M10425</guid>
      <dc:creator>richard_hu2003</dc:creator>
      <dc:date>2011-04-25T14:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/478152#M123266</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I understand that first a global table with a= cat created and then a local table with a=frog created and in the last step it is updated to pig. But when resolving a macro variable (&amp;amp;a) doesn’t SAS first look into lical table and if it finds it it retrieves it from local (hence here pig) and if it cannot find it from local table it looks into global table?</description>
      <pubDate>Sat, 14 Jul 2018 20:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/478152#M123266</guid>
      <dc:creator>shidehrafigh</dc:creator>
      <dc:date>2018-07-14T20:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/478170#M123274</link>
      <description>You are correct, but the question in the OP is based on resolving a macro variable in the global scope.</description>
      <pubDate>Sun, 15 Jul 2018 02:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/478170#M123274</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-07-15T02:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967424#M376360</link>
      <description>&lt;P&gt;program:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;%let a=20;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%&lt;STRONG&gt;macro&lt;/STRONG&gt; check;&lt;BR /&gt;%let a=50;&lt;BR /&gt;%put inside &amp;amp;a.;&lt;BR /&gt;%&lt;STRONG&gt;mend&lt;/STRONG&gt; check;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%check;&lt;BR /&gt;%put outside &amp;amp;a.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output :&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;inside 50&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;outside 50&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q: first i have defined variable a with %let , SAS will consider as global variable,&lt;/P&gt;&lt;P&gt;then same variable inside a macro ,SAS will consider as local variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But why it is printing both as 50, it should print inside 50 and outside 20 , right ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can someone explain , why local variable is over writing global macro variable ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13683"&gt;@ArtC&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21021"&gt;@richard_hu2003&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114919"&gt;@shidehrafigh&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13941"&gt;@SPR&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 14:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967424#M376360</guid>
      <dc:creator>narravulap</dc:creator>
      <dc:date>2025-05-25T14:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967425#M376361</link>
      <description>&lt;P&gt;You have not defined any local macro variable.&amp;nbsp; So only the global macro variable exists.&lt;/P&gt;
&lt;P&gt;Click on Spoiler below to see why.&lt;/P&gt;
&lt;LI-SPOILER&gt;There is no %LOCAL statement to define a local macro variable.&lt;BR /&gt;The macro does not define any parameters. Note that macro parameters are always LOCAL to the macro.&lt;BR /&gt;The %LET statement does not need to make a new macro variable since there is already a macro variable with that name.&lt;/LI-SPOILER&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/444116"&gt;@narravulap&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;program:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;%let a=20;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%&lt;STRONG&gt;macro&lt;/STRONG&gt; check;&lt;BR /&gt;%let a=50;&lt;BR /&gt;%put inside &amp;amp;a.;&lt;BR /&gt;%&lt;STRONG&gt;mend&lt;/STRONG&gt; check;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%check;&lt;BR /&gt;%put outside &amp;amp;a.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output :&lt;/P&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=""&gt;&lt;STRONG&gt;inside 50&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=""&gt;&lt;STRONG&gt;outside 50&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Q: first i have defined variable a with %let , SAS will consider as global variable,&lt;/P&gt;
&lt;P&gt;then same variable inside a macro ,SAS will consider as local variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why it is printing both as 50, it should print inside 50 and outside 20 , right ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can someone explain , why local variable is over writing global macro variable ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13683"&gt;@ArtC&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21021"&gt;@richard_hu2003&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114919"&gt;@shidehrafigh&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13941"&gt;@SPR&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 14:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967425#M376361</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-25T14:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967426#M376362</link>
      <description>creating macro variable inside a macro , automatically consider as local right, ?&lt;BR /&gt;when i'm calling outside of a macro , why it is printing local macro variable?&lt;BR /&gt;&lt;BR /&gt;%let statement inside a macro, creates a local macro variable</description>
      <pubDate>Sun, 25 May 2025 14:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967426#M376362</guid>
      <dc:creator>narravulap</dc:creator>
      <dc:date>2025-05-25T14:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967427#M376363</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/444116"&gt;@narravulap&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;creating macro variable inside a macro , automatically consider as local right, ?&lt;BR /&gt;when i'm calling outside of a macro , why it is printing local macro variable?&lt;BR /&gt;&lt;BR /&gt;%let statement inside a macro, creates a local macro variable&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The first statement is true. (Unless you use CALL SYMPUTX() with the third argument set to 'G'.)&lt;/P&gt;
&lt;P&gt;The last statement is false.&lt;/P&gt;
&lt;P&gt;Having a %LET statement inside of macro definition just means it does not execute until you call the macro.&amp;nbsp; The same as having a PROC PRINT statement inside of the macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When it does execute it only makes a NEW macro variable if the macro variable does not already exist.&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 14:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967427#M376363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-25T14:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967431#M376364</link>
      <description>Thanks for all your patients and reply, kindly elaborate below points , great help for me.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%let a=20;&lt;BR /&gt;&lt;BR /&gt;%macro check;&lt;BR /&gt;%let a=50;&lt;BR /&gt;%put inside &amp;amp;a.;&lt;BR /&gt;%mend check;&lt;BR /&gt;%check;&lt;BR /&gt;&lt;BR /&gt;%put outside &amp;amp;a.;&lt;BR /&gt;&lt;BR /&gt;1. so, if there is a macro variable already defined as global, it will be global until we mentioned as local ?&lt;BR /&gt;2. macro parameters are by default, local variables ?&lt;BR /&gt;3.Macros will be stored in different two tables right ?, then it can store separately, a=20 as global because i have derived it with open code let statement and can store a=50 in local table can be referred only during that particular macro. ?&lt;BR /&gt;4. how this storing process works in SAS for macro variables ?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Pavan.&lt;BR /&gt;</description>
      <pubDate>Sun, 25 May 2025 17:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967431#M376364</guid>
      <dc:creator>narravulap</dc:creator>
      <dc:date>2025-05-25T17:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967432#M376365</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;First, I highly recommend &lt;A title="Read the documentation." href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068/show-comments/false" target="_self"&gt;&lt;STRONG&gt;Maxim 1&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following link provides documentation page with precise diagrams explaining how macro variables are created, populated, and resolved:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0g7wk5o8cji7ln16v9bmzu5xjto.htm" target="_blank" rel="noopener"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p0g7wk5o8cji7ln16v9bmzu5xjto.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) yes, macro parameters are local by default, run the following code and see the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mv = I an global!;

%macro test(mv=am I local?);
%put _local_;
%put ##################;
%put _user_;
%mend;

%test()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log shows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    %let mv = I an global!;
2
3    %macro test(mv=am I local?);
4    %put _local_;
5    %put ##################;
6    %put _user_;
7    %mend;
8
9    %test()
TEST MV am I local?
##################
TEST MV am I local?
GLOBAL MV I an global!
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see there local table (with TEST prefix for scope) has one variable and global table has one too (with GLOBAL prefix for scope)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) and 4) If you run the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mv = I an global!;

%macro testInside(mv=I am local even more!!);
proc print data=sashelp.vmacro;
run;
%mend;

%macro test(mv=am I local?);
%put _local_;
%put ##################;
%put _user_;

%testInside()

%mend;

%test()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will see that all "available" scopes (in this case two "local" [one for test, second for testInside] and the global one) can be retrieve from one SAS view in sashelp library.&lt;/P&gt;
&lt;P&gt;Order of observations goes from the most inner one to most global one. So even if we conceptually think about 3 macro variables tables, we can get all information from one place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 18:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967432#M376365</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-05-25T18:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967434#M376366</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;1. so, if there is a macro variable already defined as global, it will be global until we mentioned as local ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;No.&amp;nbsp; If you define a global macro variable it lives forever.&amp;nbsp; Or at least it used to before SAS added the %SYMDEL macro statement.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But once you create a LOCAL macro variable with the same name you cannot see it.&amp;nbsp; Only the "inner most" or "closest" version of the macro variable can be used.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The exceptions are that you can use CALL SYMPUTX() to modify global macro variables that are hidden (blocked) by a local macro variable.&amp;nbsp; And if you want to retrieve the value of a global (or other local scope) macro variable that is hidden you can use this macro:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/symget.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/symget.sas&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;2. macro parameters are by default, local variables ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Yes.&amp;nbsp; The parameters of a macro are local macro variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;3.Macros will be stored in different two tables right ?, then it can store separately, a=20 as global because i have derived it with open code let statement and can store a=50 in local table can be referred only during that particular macro. ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Only while the macro is executing. Once the macro finishes its local macro variables are gone.&amp;nbsp; Note that if your macro calls another macro that second macro can see and modify the first's local macro variables.&amp;nbsp; Just like you can see and modify global macro variables.&amp;nbsp; As long are they are not hidden.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;4. how this storing process works in SAS for macro variables ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;No idea and it probably does not matter.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you print the SASHELP.VMACRO view (or query the DICTIONARY.MACROS table it references) you will see that each macro instance has a SCOPE.&amp;nbsp; The SCOPE is either GLOBAL (or AUTOMATIC which is just another name for GLOBAL macro variables the SAS created for you) or the name of the macro where they live.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 19:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967434#M376366</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-25T19:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967436#M376367</link>
      <description>&lt;P&gt;3)&amp;nbsp;&lt;EM&gt;Macros&lt;/EM&gt; are stored globally. Only&amp;nbsp;macro&amp;nbsp;&lt;EM&gt;variables&lt;/EM&gt; have scope.&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 20:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967436#M376367</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-05-25T20:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967447#M376368</link>
      <description>&lt;PRE&gt;%let a=cat;
%macro animal(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;a=&lt;/STRONG&gt;&lt;/FONT&gt;frog);
%let a=bird;
%mend;
%animal(a=pig)
%put a is &amp;amp;a;
&lt;/PRE&gt;
&lt;P&gt;Here keyword marco parameter 'a=' create a LOCAL macro variable &amp;amp;a in macro "%animal".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the GLOBAL macro variable &amp;amp;a. would not be updated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in your macro,you don't have it, therefore you only have a GLOBAL macro variable and this GLOBAL macro variable would be updated.&lt;/P&gt;</description>
      <pubDate>Mon, 26 May 2025 02:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967447#M376368</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-26T02:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS global macro vs local macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967530#M376379</link>
      <description>&lt;P&gt;Here is some additional documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&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;</description>
      <pubDate>Tue, 27 May 2025 11:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-global-macro-vs-local-macro/m-p/967530#M376379</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-05-27T11:18:51Z</dc:date>
    </item>
  </channel>
</rss>

