Lesson 9, Part 4: Viewing Macro Variables¶
- Referencing macro variables and displaying their values
- System-defined vs. user-defined macro variables
- Global Symbol Table vs. Local Symbol_Table
Viewing the Values of All Current Macro Variables and SAS Documentation
The easiest way to do this is to simply use the following command:
%put _ALL_;
This will list the current value of every macro variable within the SAS log.
In addition to _ALL_ you could use any of the following:
_USER_ to list only user defined macro variables;
_AUTOMATIC_ to list those defined by the SAS system;
_GLOBAL_ to list all session wide macro variables (global symbol table);
_LOCAL_ to list those macro variables local to the executing macro.
In [9]:
from IPython.display import Image
Image("C:/Data/Global_Symbol_Table.png")
Out[9]:
Macro variables defined by macro programmers are called user-defined macro variables. Those defined by the macro processor are called automatic macro variables. You can define and use macro variables anywhere in SAS programs, except within data lines.
When a macro variable is defined, the macro processor adds it to one of the program's macro variable symbol tables. The variable is held in the global symbol table, which the macro processor creates at the beginning of a SAS session when the following occurs:
* a macro variable is defined in a statement that is outside a macro definition (called open code)
* the variable is created automatically by the macro processor (except SYSPBUFF)
In [10]:
from IPython.display import Image
Image("C:/Data/Local_Symbol_Table.png")
Out[10]:
"When a macro variable is defined within a macro and is not specifically defined as global, the variable is typically held in the macro's local symbol table. SAS creates the local symbol table when the macro starts executing. For more information about symbol tables, see SAS Programs and Macro Processing and Scopes of Macro Variables."
Global Symbol Table vs. Local Symbol Table¶
In [6]:
from IPython.display import Image
Image("C:/Data/Automatic_macro_vars.png")
Out[6]:
In [1]:
from IPython.display import Image
Image("C:/Data/Percent_put.png")
Out[1]: