<?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: Retrieve a macro varible from a different scope in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/394284#M94984</link>
    <description>&lt;P&gt;At any point in a program only one value a macro variable of a given name will be available.&lt;/P&gt;
&lt;P&gt;Since you redefine the macro variable a in the macro BBB to have a value of bbb with a %let at that point the value available by referencing &amp;amp;a is the bbb. I am not sure why you pass a parameter a and then reassign the value as that is pretty nonsensical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value of a from macro aaa either pass it to bbb and don't overwrite it with a let or use a different parameter name:&lt;/P&gt;
&lt;PRE&gt;%macro aaa;
    %local a;
    %let a = 123;
    %bbb(b = &amp;amp;a)
%mend;

%macro bbb(b);
    %let a = bbb;
    %put {&amp;amp;b};
    /* here I want to get the value '123' of A macro variable from AAA scope */
%mend;

%aaa;&lt;/PRE&gt;
&lt;P&gt;will do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be in the macro AAA to create a global macro variable suchas %global AAA_A;&lt;/P&gt;
&lt;P&gt;and assign that the local a value: %let AAA_A = &amp;amp;a; and then in the bbb macro reference the global variable &amp;amp;AAA_A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I would pass the value I want as a parameter and most likely with a different name unless you actually want the bbb macro to modify the value for use inside the macro aaa.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2017 17:43:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-09-08T17:43:20Z</dc:date>
    <item>
      <title>Retrieve a macro varible from a different scope</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/394269#M94982</link>
      <description>&lt;P&gt;Greetings!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there is a way to get a macro variable from a different scope. E.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro aaa;
    %local a;
    %let a = 123;
    %bbb(a = &amp;amp;a)
%mend;

%macro bbb(a);
    %let a = bbb;
    %put {&amp;amp;a};
    /* here I want to get the value '123' of A macro variable from AAA scope */
%mend;

%aaa;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know the way to do so using PROC SQL DICTIONARY.MACROS table, but I need a pure SAS way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 16:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/394269#M94982</guid>
      <dc:creator>sspkmnd</dc:creator>
      <dc:date>2017-09-08T16:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a macro varible from a different scope</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/394284#M94984</link>
      <description>&lt;P&gt;At any point in a program only one value a macro variable of a given name will be available.&lt;/P&gt;
&lt;P&gt;Since you redefine the macro variable a in the macro BBB to have a value of bbb with a %let at that point the value available by referencing &amp;amp;a is the bbb. I am not sure why you pass a parameter a and then reassign the value as that is pretty nonsensical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value of a from macro aaa either pass it to bbb and don't overwrite it with a let or use a different parameter name:&lt;/P&gt;
&lt;PRE&gt;%macro aaa;
    %local a;
    %let a = 123;
    %bbb(b = &amp;amp;a)
%mend;

%macro bbb(b);
    %let a = bbb;
    %put {&amp;amp;b};
    /* here I want to get the value '123' of A macro variable from AAA scope */
%mend;

%aaa;&lt;/PRE&gt;
&lt;P&gt;will do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be in the macro AAA to create a global macro variable suchas %global AAA_A;&lt;/P&gt;
&lt;P&gt;and assign that the local a value: %let AAA_A = &amp;amp;a; and then in the bbb macro reference the global variable &amp;amp;AAA_A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I would pass the value I want as a parameter and most likely with a different name unless you actually want the bbb macro to modify the value for use inside the macro aaa.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 17:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/394284#M94984</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-08T17:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve a macro varible from a different scope</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/484915#M125923</link>
      <description>&lt;P&gt;For anyone interested in the answer, Scott Bass &lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/symget.sas" target="_self"&gt;open-sourced a macro&lt;/A&gt; (originally Written by Tom Abernathy (via SAS-L posting), see header for more details) to utilize the above problem (implemented via &lt;FONT face="andale mono,times"&gt;SASHELP.VMACRO&lt;/FONT&gt;&amp;nbsp;in a pure SAS Macro).&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 21:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieve-a-macro-varible-from-a-different-scope/m-p/484915#M125923</guid>
      <dc:creator>sspkmnd</dc:creator>
      <dc:date>2018-08-07T21:15:24Z</dc:date>
    </item>
  </channel>
</rss>

