How the Macro Processor Compiles a Macro Definition

When you submit a SAS program, the contents of the program goes to an area of memory called the input stack. The example program in the following figure contains a macro definition, a macro call, and a PROC PRINT step. This section illustrates how the macro definition in the example program is compiled and stored.
The Macro APP
Macro APP in the Input Stack
Using the same process described in SAS Programs and Macro Processing the word scanner begins tokenizing the program. When the word scanner detects % followed by a nonblank character in the first token, it triggers the macro processor. The macro processor examines the token and recognizes the beginning of a macro definition. The macro processor pulls tokens from the input stack and compiles until the %MEND statement terminates the macro definition (Macro APP in the Input Stack).
During macro compilation, the macro processor does the following:
  • creates an entry in the session catalog
  • compiles and stores all macro program statements for that macro as macro instructions
  • stores all noncompiled items in the macro as text
    Note: Text items are underlined in the illustrations in this section.
If the macro processor detects a syntax error while compiling the macro, it checks the syntax in the rest of the macro and issues messages for any additional errors that it finds. However, the macro processor does not store the macro for execution. A macro that the macro processor compiles but does not store is called a dummy macro.
Macro APP in the Input Stack
Macro APP in the Input Stack
In this example, the macro definition is compiled and stored successfully. (See the following figure.) For the sake of illustration, the compiled APP macro looks like the original macro definition that was in the input stack. The entry would actually contain compiled macro instructions with constant text. The constant text in this example is underlined.
The Compiled Macro APP
The Compiled Macro APP