Chapter Contents

Previous

Next
SAS Macro Language: Reference

Introduction

Every macro variable has a scope.(footnote 1) A macro variable's scope determines how it is assigned values and how the macro processor resolves references to it.

Two types of scope exist for macro variables: global and local. Global macro variables exist for the duration of the SAS session and can be referenced anywhere in the program--either inside or outside a macro. Local macro variables exist only during the execution of the macro in which the variables are created and have no meaning outside the defining macro.

Scopes can be nested, like boxes within boxes. For example, suppose you have a macro A that creates the macro variable LOC1 and a macro B that creates the macro variable LOC2. If the macro B is nested (executed) within the macro A, LOC1 is local to both A and B. However, LOC2 is local only to B.

Macro variables are stored in symbol tables, which list the macro variable name and its value. There is a global symbol table, which stores all global macro variables. Local macro variables are stored in a local symbol table that is created at the beginning of the execution of a macro.


FOOTNOTE 1:  Earlier macro facility documentation often used the term "referencing environment" instead of scope. [arrow]


Chapter Contents

Previous

Next

Top of Page

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