Details
If macro-variable exists in any enclosing scope, macro-variable is updated. If macro-
variable does not exist, SYMPUT creates it. (See below to determine in which scope
SYMPUT creates macro-variable.) SYMPUT makes a macro variable assignment when
the program executes.
SYMPUT can be used in all SAS language programs, including SCL programs. Because
it resolves variables at program execution instead of macro execution, SYMPUT should
be used to assign macro values from DATA step views, SQL views, and SCL programs.
Scope of Variables Created with SYMPUT
SYMPUT puts the macro variable in the most local nonempty symbol table. A symbol
table is nonempty if it contains the following:
• a value
• a computed %GOTO (A computed %GOTO contains %or & and resolves to a label.)
• the macro variable &SYSPBUFF, created at macro invocation time.
However, there are three cases where SYMPUT creates the variable in the local symbol
table, even if that symbol table is empty:
• Beginning with Version 8, if SYMPUT is used after a PROC SQL, the variable will
be created in a local symbol table.
• If an executing macro contains a computed %GOTO statement and uses SYMPUT to
create a macro variable, the variable is created in the local symbol table.
• If an executing macro uses &SYSPBUFF and SYMPUT to create a macro variable,
the macro variable is created in the local symbol table.
For more information about creating a variable with SYMPUT, see “Scopes of Macro
Variables” on page 49.
Problem Trying to Reference a SYMPUT-Assigned Value Before It Is Available
One of the most common problems in using SYMPUT is trying to reference a macro
variable value assigned by SYMPUT before that variable is created. The failure
generally occurs because the statement referencing the macro variable compiles before
execution of the CALL SYMPUT statement that assigns the variable's value. The most
important fact to remember in using SYMPUT is that it assigns the value of the macro
variable during program execution. Macro variable references resolve during the
compilation of a step, a global statement used outside a step, or an SCL program. As a
result:
• You cannot use a macro variable reference to retrieve the value of a macro variable
in the same program (or step) in which SYMPUT creates that macro variable and
assigns it a value.
• You must specify a step boundary statement to force the DATA step to execute
before referencing a value in a global statement following the program (for example,
a TITLE statement). The boundary could be a RUN statement or another DATA or
PROC statement. For example:
data x;
x='December';
call symput('var',x);
proc print;
title "Report for &var";
run;
Processing on page 39 provides details about compilation and execution.
242 Chapter 15 • DATA Step Call Routines for Macros