Previous Page | Next Page

Scopes of Macro Variables

Global Macro Variables

The following figure illustrates the global symbol table during execution of the following program:

%let county=Clark;

%macro concat;
   data _null_;
      length longname $20;
      longname="&county"||" County";
      put longname;
   run;
%mend concat;

%concat

Calling the macro CONCAT produces the following statements:

data _null_;
      length longname $20;
      longname="Clark"||" County";
      put longname;
run;

The PUT statement writes the following to the SAS log:

Clark County

Global Symbol Table

[Global Macro Variables]

Global macro variables include the following:

You can create global macro variables any time during a SAS session or job. Except for some automatic macro variables, you can change the values of global macro variables any time during a SAS session or job.

In most cases, once you define a global macro variable, its value is available to you anywhere in the SAS session or job and can be changed anywhere. So, a macro variable referenced inside a macro definition is global if a global macro variable already exists by the same name (assuming that the variable is not specifically defined as local with the %LOCAL statement or in a parameter list). The new macro variable definition simply updates the existing global one. The following are exceptions that prevent you from referencing the value of a global macro variable:

You can use the %SYMGLOBL function to indicate whether an existing macro variable resides in the global symbol table. See the %SYMGLOBL Function for more detailed information.

Previous Page | Next Page | Top of Page