<?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 macro stored in global/local symbol table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/539990#M148895</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am studying for SAS Advanced programmer certificate.&lt;/P&gt;&lt;P&gt;I can't solve this problem. This is the exam question:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one (input);
       %two;
       %put the value is &amp;amp;date;
%mend;

%macro two;
data _null_;
	call symput('date','12SEP2008');
run;
%mend;

%let date = 31DEC2006;
%one (&amp;amp;date);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What is the result&amp;nbsp;when the %put&amp;nbsp;statement executes?&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the local symbol table for the ONE macro&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the local symbol table for the&amp;nbsp;TWO macro&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the global symbol table&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value&amp;nbsp;31DEC2006 is retrived from the global symbol table&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The correct answer is the 3. But I can't understand why. I thought the corret anserw was 2 and the macro was stored in the local symble table beacause the code is inside of a macro defintion.&lt;/P&gt;&lt;P&gt;Can you help me? Thanks a lot,&lt;/P&gt;&lt;P&gt;Daniele&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2019 10:25:48 GMT</pubDate>
    <dc:creator>Ccasagran737</dc:creator>
    <dc:date>2019-03-04T10:25:48Z</dc:date>
    <item>
      <title>macro stored in global/local symbol table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/539990#M148895</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am studying for SAS Advanced programmer certificate.&lt;/P&gt;&lt;P&gt;I can't solve this problem. This is the exam question:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one (input);
       %two;
       %put the value is &amp;amp;date;
%mend;

%macro two;
data _null_;
	call symput('date','12SEP2008');
run;
%mend;

%let date = 31DEC2006;
%one (&amp;amp;date);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What is the result&amp;nbsp;when the %put&amp;nbsp;statement executes?&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the local symbol table for the ONE macro&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the local symbol table for the&amp;nbsp;TWO macro&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value 12SEP2008 is retrived from the global symbol table&lt;/LI&gt;&lt;LI&gt;A macro variable DATE with the value&amp;nbsp;31DEC2006 is retrived from the global symbol table&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The correct answer is the 3. But I can't understand why. I thought the corret anserw was 2 and the macro was stored in the local symble table beacause the code is inside of a macro defintion.&lt;/P&gt;&lt;P&gt;Can you help me? Thanks a lot,&lt;/P&gt;&lt;P&gt;Daniele&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 10:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/539990#M148895</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2019-03-04T10:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro stored in global/local symbol table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/539998#M148901</link>
      <description>Defining the macros doesn't create any macro variables.  The first statement here that actually executes is &lt;BR /&gt;&lt;BR /&gt;%let date = 31DEC2006;&lt;BR /&gt;&lt;BR /&gt;Since that appears outside of any macro definition, it creates &amp;amp;DATE in the global symbol table.&lt;BR /&gt;&lt;BR /&gt;Next, the macros execute.  Since &amp;amp;DATE already exists, neither macro creates a new variable.  Both use the existing global &amp;amp;DATE.</description>
      <pubDate>Mon, 04 Mar 2019 11:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/539998#M148901</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-04T11:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: macro stored in global/local symbol table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/540132#M148948</link>
      <description>&lt;P&gt;One reason that the answer cannot be 2 is because the macro TWO does not have ANY local macro variables.&lt;/P&gt;
&lt;P&gt;You can demonstrate by pulling from the SASHELP.VMACRO metadata table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro three;
%let local3_mvar=This is local to THREE;
data _null_;
  set sashelp.vmacro ;
  where scope not in ('AUTOMATIC' 'GLOBAL')
     or name = 'DATE'
  ;
  put (_all_) (=);
run;
%mend three;

%macro two;
data _null_;
	call symput('date','12SEP2008');
run;
%three;
%mend;

%macro one (input);
%two;
%put the value is &amp;amp;date;
%mend;

%let date = 31DEC2006;
options mprint;
%one (&amp;amp;date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;MPRINT(TWO):   data _null_;
MPRINT(TWO):   call symput('date','12SEP2008');
MPRINT(TWO):   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


MPRINT(THREE):   data _null_;
MPRINT(THREE):   set sashelp.vmacro ;
MPRINT(THREE):   where scope not in ('AUTOMATIC' 'GLOBAL') or name = 'DATE' ;
MPRINT(THREE):   put (_all_) (=);
MPRINT(THREE):   run;

scope=THREE name=LOCAL3_MVAR offset=0 value=This is local to THREE
scope=ONE name=INPUT offset=0 value=31DEC2006
scope=GLOBAL name=DATE offset=0 value=12SEP2008
NOTE: There were 3 observations read from the data set SASHELP.VMACRO.
      WHERE scope not in ('AUTOMATIC', 'GLOBAL') or (name='DATE');
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


MPRINT(TWO):  ;
MPRINT(ONE):  ;
the value is 12SEP2008
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 18:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/540132#M148948</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-04T18:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: macro stored in global/local symbol table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/540138#M148951</link>
      <description>&lt;P&gt;While you're learning about MACRO scope, you might test out what happens if you remove the %LET statement, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one (input);
       %two;
       %put the value is &amp;amp;date;
%mend;

%macro two;
data _null_;
	call symput('date','12SEP2008');
run;
%put _user_ ;
%mend;

/*%let date = 31DEC2006;*/
%one (31DEC2006)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which scope would you expect the macro variable DATE to be created in now?&amp;nbsp; &amp;nbsp;CALL SYMPUT has some interesting rules it uses when deciding where to write a macro variable, but&amp;nbsp; I won't spoil the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, this is a good example of why life is much easier if you explicitly declare macro variables as %local to the macro where they are created, rather than rely on the hope that SAS will make them local for you.&amp;nbsp; (Also the newer CALL SYMPUTX allows you to specify a scope).&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 18:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-stored-in-global-local-symbol-table/m-p/540138#M148951</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-03-04T18:36:42Z</dc:date>
    </item>
  </channel>
</rss>

