Previous Page | Next Page

Macro Statements

%GLOBAL Statement



Creates macro variables that are available during the execution of an entire SAS session.
Type: Macro statement
Restriction: Allowed in macro definitions or open code
See also: %LOCAL Statement

Syntax
Details
Comparisons
Example
Creating Global Variables in a Macro Definition

Syntax

%GLOBAL macro-variable-1 <...macro-variable-n>;

macro-variable-1 <...macro-variable-n>

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 %GLOBAL statement.


Details

The %GLOBAL statement creates one or more global macro variables and assigns null values to the variables. Global macro variables are variables that are available during the entire execution of the SAS session or job.

A macro variable created with a %GLOBAL statement has a null value until you assign it some other value. If a global macro variable already exists and you specify that variable in a %GLOBAL statement, the existing value remains unchanged.


Comparisons


Example


Example 1: Creating Global Variables in a Macro Definition

%macro vars(first=1,last=);
   %global gfirst glast;
   %let gfirst=&first;
   %let glast=&last;
   var test&first-test&last;
%mend vars;

When you submit the following program, the macro VARS generates the VAR statement and the values for the macro variables used in the title statement.

proc print;
   %vars(last=50)
   title "Analysis of Tests &gfirst-&glast";
run;

SAS sees the following:

PROC PRINT;
   VAR TEST1-TEST50;
   TITLE "Analysis of Tests 1-50";
RUN;

Previous Page | Next Page | Top of Page