Macro execution begins with
the macro processor opening the SASMACR catalog to read the appropriate
macro entry. As the macro processor executes the compiled instructions
in the macro entry, it performs a series of simple repetitive actions.
During macro execution, the macro processor does the following:
-
executes compiled macro program
instructions
-
places noncompiled constant text
on the input stack
-
waits for the word scanner to process
the generated text
-
resumes executing compiled macro
program instructions
To continue the example
from the previous section, the following figure shows the lines remaining
in the input stack after the macro processor compiles the macro definition
APP.
The word scanner examines
the input stack and detects % followed by a nonblank character in
the first token. It triggers the macro processor to examine the token.
The macro processor
recognizes a macro call and begins to execute macro APP, as follows:
-
The macro processor
creates a local symbol table for the macro. The macro processor examines
the previously compiled definition of the macro. If there are any
parameters, variable declarations, or computed GOTO statements in
the macro definition, the macro processor adds entries for the parameters
and variables to the newly created local symbol table.
-
The macro processor
further examines the previously compiled macro definition for parameters
to the macro. If no parameters were defined in the macro definition,
the macro processor begins to execute the compiled instructions of
the macro. If any parameters were contained in the definition, the
macro processor removes tokens from the input stack to obtain values
for positional parameters and non-default values for keyword parameters.
The values for parameters found in the input stack are placed in
the appropriate entry in the local symbol table.
Note: Before executing any compiled
instructions, the macro processor removes only enough tokens from
the input stack to ensure that any tokens that are supplied by the
user and pertain to the macro call have been removed.
-
The macro processor
encounters the compiled %IF instruction and recognizes that the next
item will be text containing a condition.
-
The macro processor
places the text
&sysday=Friday
on the
input stack ahead of the remaining text in the program. (See the following
figure). The macro processor waits for the word scanner to tokenize
the generated text.
-
The word scanner starts
tokenizing the generated text, recognizes an ampersand followed by
nonblank character in the first token, and triggers the macro processor.
-
The macro processor
examines the token and finds a possible macro variable reference,
&SYSDAY. The macro processor first searches the local APP symbol
table for a matching entry and then the global symbol table. When
the macro processor finds the entry in the global symbol table, it
replaces macro variable in the input stack with the value
Friday
. (See the following figure.)
-
The macro processor
stops and waits for the word scanner to tokenize the generated text.
-
The word scanner then
read
Friday=Friday
from the input stack.
-
The macro processor
evaluates the expression
Friday=Friday
and,
because the expression is true, proceeds to the %THEN and %DO instructions.
-
The macro processor
executes the compiled %DO instructions and recognizes that the next
item is text.
-
The macro processor
places the text on top of the input stack and waits for the word scanner
to begin tokenization.
-
The word scanner reads
the generated text from the input stack, and tokenizes it.
-
The word scanner recognizes
the beginning of a DATA step, and triggers the compiler to begin accepting
tokens. The word scanner transfers tokens to the compiler from the
top of the stack.
-
When the word scanner
detects & followed by a nonblank character (the macro variable
reference &GOAL), it triggers the macro processor.
-
The macro processor
looks in the local APP symbol table and resolves the macro variable
reference &GOAL to
10000
. The macro
processor places the value on top of the input stack, ahead of the
remaining text in the program.
-
The word scanner resumes
tokenization. When it has completed tokenizing the generated text,
it triggers the macro processor.
-
The macro processor
resumes processing the compiled macro instructions. It recognizes
the end of the %DO group at the %END instruction and proceeds to %MEND.
-
the macro processor
executes the %MEND instruction, removes the local symbol table APP,
and macro APP ceases execution.
-
The macro processor
triggers the word scanner to resume tokenization.
-
The word scanner reads
the first token in the input stack (PROC), recognizes the beginning
of a step boundary, and triggers the DATA step compiler.
-
The compiled DATA step
is executed, and the DATA step compiler is cleared.
-
The word scanner signals
the PRINT procedure (a separate executable not illustrated), which
pulls the remaining tokens.