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
%end;
%mend totinv;
%let trace=ON;
%totinv(price)
%put *** TOTAL=&macvar ***;
The first %PUT statement in the macro TOTINV writes the message about tracing being
on and then writes the scope and value of all user-generated macro variables to the SAS
log.
*** Tracing macro scopes. ***
TOTINV VAR price
GLOBAL TRACE ON
GLOBAL MACVAR $1,240,800.00
*** TOTAL= $1,240,800.00 ***
For a more detailed discussion of macro variable scopes, see Chapter 5, “Scopes of
Macro Variables,” on page 49.
142 Chapter 10 Macro Facility Error Messages and Debugging
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset