Chapter Contents

Previous

Next
SAS Macro Language: Reference

How the Macro Processor Executes a Compiled Macro

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

To continue the example from the previous section, The Macro Call in the Input Stack shows the lines remaining in the input stack after the macro processor compiles the macro definition APP.

The Macro Call in the Input Stack

[IMAGE]

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 (Macro Call Entering Word Queue).

Macro Call Entering Word Queue

[IMAGE]

The macro processor recognizes a macro call and begins to execute macro APP, as follows:

  1. The macro processor opens the session catalog and creates a local symbol table with an entry for the parameter GOAL.

  2. The macro processor removes the tokens for the macro call from the input stack and places the parameter value in GOAL entry in the APP symbol table.

  3. The macro processor encounters the compiled %IF instruction and recognizes that the next item will be text containing a condition.

  4. The macro processor places the text &sysday=Friday on the input stack ahead of the remaining text in the program (Text for %IF Condition on Input Stack) and waits for the word scanner to tokenize the generated text.

Text for %IF Condition on Input Stack

[IMAGE]

  1. The word scanner starts tokenizing the generated text, recognizes an ampersand followed by nonblank character in the first token, and triggers the macro processor.

  2. The macro processor examines the token, 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 (Figure 4.7).

  3. The macro processor stops and waits for the word scanner to tokenize the generated text.

Input Stack after Macro Variable Reference Is Resolved

[IMAGE]

  1. The word scanner then read Friday=Friday from the input stack.

  2. The macro processor evaluates the expression Friday=Friday and, because the expression is true, proceeds to the %THEN and %DO instructions (Figure 4.8).

Macro Processor Receives the Condition

[IMAGE]

  1. The macro processor executes the compiled %DO instructin and recognizes that the next item is text.

  2. The macro processor places the text on top of the input stack and waits for the word scanner to begin tokenization.

  3. The word scanner reads the generated text from the input stack, and tokenizes it.

  4. 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 (Figure 4.9).

Generated Text on Top of Input Stack

[IMAGE]

  1. When the word scanner detects & followed by a nonblank characater (the macro variable refernece &GOAL), it triggers the macro processor.

  2. 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 (Figure 4.10).

The Word Scanner Reads Generated Text

[IMAGE]

  1. The word scanner resumes tokenization. When it has completed tokenizing the generated text, it triggers the macro processor.

  2. The macro processor resumes processing the compiled macro instructions. It recognizes the end of the %DO group at the %END instructin and proceeds to %MEND.

  3. the macro processor executes the %MEND instruction, removes the local symbol table APP, and macro APP ceases execution.

  4. The macro processor triggers the word scanner to resume tokenization.

  5. The word scanner reads the first token in input stack (PROC), recognizes the beginning of a step boundary, and triggers the DATA step compiler.

  6. The compiled DATA step is executed, and the DATA step compiler is cleared.

  7. The word scanner signals the PRINT procedure (a separate executable not illustrated), which pulls the remaining tokens.

The Remaining Statements are Compiled and Executed

[IMAGE]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.