variX and assigns a value of one to it. Then Outer calls another macro program named Inner. The macro named Inner creates a local macro variable named variY and assigns the value of variX to it. %macro outer;
%local variX;
%let variX=one;
%inner
%mend outer;
%macro inner;
%local variY;
%let variY=&variX;
%mend inner;Let's examine what happens to the symbol tables when you submit the following code: %let variX=zero;
%outer
- The macro processor receives
%let variX=zero;. It checks the global symbol table for a macro variable namedvariX. There is none, so the macro processor createsvariXand assigns a value of zero to it.Global Symbol Table variXzero - The macro processor receives
%outer. The macro processor retrieves the macro Outer from Work.Sasmacr, then begins executing it. - The macro processor encounters
%local variX;. It creates a local symbol table. The macro processor creates the macro variablevariXin this local table and assigns a null value to it. This does not affect the macro variablevariXthat is stored in the global symbol table.Global Symbol Table variXzero Outer Local Symbol Table variX - The macro processor encounters
%let variX=one;. The macro processor checks the local symbol table forvariXand assigns a value of one to it.Global Symbol Table variXzero Outer Local Symbol Table variXone - The macro processor receives
%inner. It retrieves the macro Inner from Work.Sasmacr, then begins executing it. - The macro processor encounters
%local variY;. It creates a local symbol table. The macro processor creates a macro variablevariYin this table and assigns a null value to it. There are now two local symbol tables in existence.Global Symbol Table variXzero Outer Local Symbol Table variXone Inner Local Symbol Table variY - The macro processor encounters
%let variY=&variX;. It checks the most recently created local table forvariX. There is no such macro variable in that symbol table, so the macro processor then checks the other local symbol table. It retrieves the value one from that symbol table and substitutes the value into the %LET statement. Then the macro processor checks the most recently created local symbol table for a macro variable namedvariY. When it finds this macro variable, it assigns the value one to it.Global Symbol Table variXzero Outer Local Symbol Table variXone Inner Local Symbol Table variYone - The Inner macro finishes executing, and the local symbol table that was created within this macro is deleted. There is now only one local symbol table in existence.
Global Symbol Table variXzero Outer Local Symbol Table variXone - The Outer macro finishes executing, and the local symbol table that was created within this macro is deleted. There are now no local symbol tables in existence. The global symbol table has not been changed since
variXwas created and was assigned a value of zero.Global Symbol Table variXzero
As you can see, each macro program in the example above has its own local symbol table that exists as long as the macro executes. When a macro finishes executing, its local symbol table and all of the local macro variables that are contained in that table are erased. The global symbol table and all of the global macro variables that are contained in it remain.
zz from sas online tutor for adv
ReplyDelete