Chapter Contents

Previous

Next
SAS Macro Language: Reference

Local Macro Variables

Local macro variables are defined within an individual macro. Each macro you invoke creates its own local symbol table. Local macro variables exist only as long as a particular macro executes; when the macro stops executing, all local macro variables for that macro cease to exist.

Local Macro Variables illustrates the local symbol table during the execution of the macro HOLINFO.

%macro holinfo(day,date);
   %let holiday=Christmas;
   %put *** Inside macro: ***;
   %put *** &holiday occurs on &day, &date, 1997. ***;
%mend holinfo;

%holinfo(Thursday,12/25)

%put *** Outside macro: ***;
%put *** &holiday occurs on &day, &date, 1997. ***;

The %PUT statements write the following to the SAS log:

*** Inside macro: ***
*** Christmas occurs on Thursday, 12/25, 1997. ***

*** Outside macro: ***
WARNING: Apparent symbolic reference HOLIDAY not resolved.
WARNING: Apparent symbolic reference DAY not resolved.
WARNING: Apparent symbolic reference DATE not resolved.
*** &holiday occurs on &day, &date, 1997. ***

As you can see from the log, the local macro variables DAY, DATE, and HOLIDAY resolve inside the macro, but outside the macro they do not exist and therefore do not resolve.

Local Macro Variables

[IMAGE]

A macro's local symbol table is empty until the macro creates at least one macro variable. A local symbol table can be created by any of the following:

Note:   Macro parameters are always local to the macro that defines them. You cannot make macro parameters global. (Although, you can assign the value of the parameter to a global variable; see "Creating Global Variables Based on the Value of Local Variables" later in this chapter.)  [cautionend]

When you invoke one macro inside another, you create nested scopes. Because you can have any number of levels of nested macros, your programs can contain any number of levels of nested scopes.


Chapter Contents

Previous

Next

Top of Page

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