Situation Example
Check leading or trailing blanks in a variable's
value
%PUT ***&variable-name***;
Check double-ampersand resolution, as during
a loop
%PUT ***variable-name&i =
&&variable-name***;
Check evaluation of a condition
%PUT ***This condition was
met.***;
As you recall, macro variables are stored in symbol tables. There is a global symbol
table, which contains global macro variables, and a local symbol table, which contains
local macro variables. During the debugging process, you might find it helpful to print
these tables occasionally to examine the scope and values of a group of macro variables.
To do so, use the %PUT statement with one of the following options:
_ALL_
describes all currently defined macro variables, regardless of scope. User-generated
global and local variables as well as automatic macro variables are included.
_AUTOMATIC_
describes all automatic macro variables. The scope is listed as AUTOMATIC. All
automatic macro variables are global except SYSPBUFF.
_GLOBAL_
describes all global macro variables that were not created by the macro processor.
The scope is listed as GLOBAL. Automatic macro variables are not listed.
_LOCAL_
describes user-generated local macro variables defined within the currently executing
macro. The scope is listed as the name of the macro in which the macro variable is
defined.
_USER_
describes all user-generated macro variables, regardless of scope. For global macro
variables, the scope is GLOBAL; for local macro variables, the scope is the name of
the macro.
The following example uses the %PUT statement with the argument _USER_ to
examine the global and local variables available to the macro TOTINV. Notice the use of
the user-generated macro variable TRACE to control when the %PUT statement writes
values to the log.
%macro totinv(var);
%global macvar;
data inv;
retain total 0;
set Sasuser.Houses end=final;
total=total+&var;
if final then call symput("macvar",put(total,dollar14.2));
run;
%if &trace = ON %then
%do;
%put *** Tracing macro scopes. ***;
%put _USER_;
Debugging Techniques 141