Macro Processing |
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.
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 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.
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.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.