Chapter Contents

Previous

Next
SAS Macro Language: Reference

Introduction

Macro variables are tools that enable you to dynamically modify the text in a SAS program through symbolic substitution. You can assign large or small amounts of text to macro variables, and after that, you can use that text by simply referencing the variable that contains it.

Macro variable values have a maximum length of 32K characters. The length of a macro variable is determined by the text assigned to it instead of an explicit length declaration. So its length varies with each value it contains. Macro variables contain only character data. However, the macro facility has features that allow a variable to be evaluated as a number when it contains a value that can be interpreted as a number. The value of a macro variable remains constant until it is explicitly changed. Macro variables are independent of SAS data set variables.

Macro variables defined by macro programmers are called user-defined macro variables. Those defined by the SAS System are called automatic macro variables. You can define and use macro variables anywhere in SAS programs, except within data lines.

When a macro variable is defined, the macro processor adds it to one of the program's macro variable symbol tables. When a macro variable is defined in a statement that is outside a macro definition (called open code) or when the variable is created automatically by the SAS System (except SYSPBUFF), the variable is held in the global symbol table, which SAS creates at the beginning of a SAS session. When a macro variable is defined within a macro and is not explicitly defined as global, the variable is typically held in the macro's local symbol table, which SAS creates when the macro starts executing. For more information about symbol tables, see Chapter 2, "SAS Programs and Macro Processing" and Chapter 5, "Scope of Macro Variables."

When it is in the global symbol table, a macro variable exists for the remainder of the current SAS session. A variable in the global symbol table is called a global macro variable. It has global scope because its value is available to any part of the SAS session.

When it is in a local symbol table, a macro variable exists only during execution of the macro in which it is defined. A variable in a local symbol table is called a local macro variable. It has local scope because its value is available only until the macro stops executing. Chapter 2 contains figures that illustrate a program with a global and a local symbol table.

You can use the %PUT statement to view all macro variables available in a current SAS session. See %PUT in Chapter 13, "Macro Language Dictionary," and also in Chapter 10, "Macro Facility Error Messages and Debugging."


Chapter Contents

Previous

Next

Top of Page

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