Chapter Contents

Previous

Next
%LOCAL

%LOCAL



Creates macro variables that are available only during the execution of the macro where they are defined

Type: Macro statement
Restriction: Allowed in macro definitions only
See also: %GLOBAL


Syntax
Details
Comparisons
Example
Using a Local Variable with the Same Name as a Global Variable

Syntax

%LOCALmacro-variable(s);

macro-variable(s)
is the name of one or more macro variables or a text expression that generates one or more macro variable names. You cannot use a SAS variable list or a macro expression that generates a SAS variable list in a %LOCAL statement.


Details

The %LOCAL statement creates one or more local macro variables. A macro variable created with %LOCAL has a null value until you assign it some other value. Local macro variables are variables that are available only during the execution of the macro in which they are defined.

Use the %LOCAL statement to ensure that macro variables created earlier in a program are not inadvertently changed by values assigned to variables with the same name in the current macro. If a local macro variable already exists and you specify that variable in a %LOCAL statement, the existing value remains unchanged.


Comparisons


Example

Example 1: Using a Local Variable with the Same Name as a Global Variable

%let variable=1;

%macro routine;
   %put ***** Beginning ROUTINE *****;
   %local variable;
   %let variable=2;
   %put The value of variable inside ROUTINE is &variable;
   %put ***** Ending ROUTINE *****;
%mend routine;

%routine
%put The value of variable outside ROUTINE is &variable;

Submitting these statements writes these lines to the SAS log:

***** Beginning ROUTINE *****
The value of variable inside ROUTINE is 2
***** Ending ROUTINE *****
The value of variable outside ROUTINE is 1


Chapter Contents

Previous

Next

Top of Page

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