T I P Leading and trailing blanks in the value are ignored. To have leading and
trailing blanks contained in the value, you must enclose the value within the
%STR function.
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.
%GLOBAL statements that use the READONLY option create a new global macro
variable and assign the specified value. Existing macro variables cannot be made read-
only. The value of the global macro variable cannot be changed and the variable cannot
be deleted. A macro variable that is declared with the READONLY option cannot be re-
declared in the same scope or any enclosed scope. All read-only macro variables persist
until the scope in which they exist is deleted.
Comparisons
• Both the %GLOBAL statement and the %LOCAL statement create macro variables
with a specific scope. However, the %GLOBAL statement creates global macro
variables that exist for the duration of the session or job. The %LOCAL statement
creates local macro variables that exist only during the execution of the macro that
defines the variable.
• If you define both a global macro variable and a local macro variable with the same
name, the macro processor uses the value of the local variable during the execution
of the macro that contains the local variable. When the macro that contains the local
variable is not executing, the macro processor uses the value of the global variable.
Example: 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;
%GLOBAL Statement 315