dsn
and vars
.
The %LET statements assign values to the new global macro variables,
as follows: %macro printdsn; %global dsn vars; %let dsn=sasuser.courses; %let vars=course_title course_code days; proc print data=&dsn; var &vars; title "Listing of &dsn data set"; run; %mend; %printdsn
dsn
from
the global symbol table, you submit the following statement: %symdel dsn;
dsn
and
assigns a value of sasuser.courses
to
it.
dsn
,
and the %LET statement within the macro definition assigns a value
of sasuser.register
to the local variable dsn
.
dsn
to
the SAS log, whereas the %PUT statement that follows the macro definition
writes the value of the global variable dsn
to
the SAS log: %let dsn=sasuser.courses; %macro printdsn; %local dsn; %let dsn=sasuser.register; %put The value of DSN inside Printdsn is &dsn; %mend; %printdsn %put The value of DSN outside Printdsn is &dsn;
199 %let dsn=sasuser.courses; 200 201 %macro printdsn; 202 %local dsn; 203 %let dsn=sasuser.register; 204 %put The value of DSN inside Printdsn is &dsn; 205 %mend; 206 207 %printdsn The value of DSN inside Printdsn is sasuser.register 208 %put The value of DSN outside Printdsn is &dsn; The value of DSN outside Printdsn is sasuser.courses |
%let macvar=value;The macro processor processes the following steps:
&macvarThe macro processor takes the following steps:
&macvar
) in open code, it checks only
the global symbol table for existence of the macro variable. If a
macro program is not currently executing, a local symbol table does
not currently exist.
Outer
and Inner
,
have been compiled. The macro named Outer
creates
a local macro variable named 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 variX=zero; %outer
%let variY=&variX;
. It checks
the most recently created local table for variX
.
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 named variY
. When it
finds this macro variable, it assigns the value one to
it.
General form, MPRINTNEST
option:
OPTIONS MPRINTNEST | NOMPRINTNEST;
MPRINTNEST
specifies that macro
nesting information is written in the MPRINT output in the SAS log.
NOMPRINTNEST
specifies that macro
nesting information is not written in the MPRINT output in the SAS
log.
|
%macro outer; data _null_; %inner run; %mend outer; %macro inner; put %inrmost; %mend inner; %macro inrmost; 'This is the text of the PUT statement' %mend inrmost;
Outer
macro,
as follows: options mprint mprintnest; %outer
MPRINT(OUTER): data _null_; MPRINT(OUTER.INNER): put MPRINT(OUTER.INNER.INRMOST): 'This is the text of the PUT statement' MPRINT(OUTER.INNER): ; MPRINT(OUTER): run; This is the text of the PUT statement NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds |
General form, MLOGICNEST
option:
OPTIONS MLOGICNEST | NOMLOGICNEST;
MLOGICNEST
specifies that macro
nesting information is written in the MLOGIC output in the SAS log.
NOMLOGICNEST
specifies that macro
nesting information is not written in the MLOGIC output in the SAS
log.
|
%macro outer; %put THIS IS OUTER; %inner %mend outer; %macro inner; %put THIS IS INNER; %inrmost %mend inner; %macro inrmost; %put THIS IS INRMOST; %mend inrmost;
Outer
macro,
as follows: options mlogic mlogicnest; %outer
MLOGIC(OUTER): Beginning execution. MLOGIC(OUTER): %PUT THIS IS OUTER THIS IS OUTER MLOGIC(OUTER.INNER): Beginning execution. MLOGIC(OUTER.INNER): %PUT THIS IS INNER THIS IS INNER MLOGIC(OUTER.INNER.INRMOST): Beginning execution. MLOGIC(OUTER.INNER.INRMOST): %PUT THIS IS INRMOST THIS IS INRMOST MLOGIC(OUTER.INNER.INRMOST): Ending execution. MLOGIC(OUTER.INNER): Ending execution. MLOGIC(OUTER): Ending execution. |