When you submit a macro definition, the macro processor compiles the definition and
produces a member in the session catalog. The member consists of compiled macro
program statements and text. The distinction between compiled items and noncompiled
(text) items is important for macro execution. Examples of text items include:
macro variable references
nested macro calls
macro functions, except %STR and %NRSTR
arithmetic and logical macro expressions
text to be written by %PUT statements
field definitions in %WINDOW statements
model text for SAS statements and SAS windowing environment commands
When you want to call the macro, you use the form
%macro_name.
Note: If your macro_text contains passwords that you want to prevent from being
revealed in the SAS log, redirect the SAS log to a file. For more information, see
“PRINTTO Procedure” in Base SAS Procedures Guide.
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.
Figure 4.1 The Macro APP
Using the same process described in Chapter 2, “SAS Programs and Macro Processing,”
on page 15 the word scanner begins tokenizing the program. When the word scanner
40 Chapter 4 Macro Processing
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 (Figure 4.2 on page 41).
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.
Figure 4.2 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.
How the Macro Processor Compiles a Macro Definition 41
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset