Troubleshooting Macro Variable References

When you submit a macro variable reference, the macro processor resolves the reference and passes the value directly back to the input stack. You will not see the value that the compiler receives. To debug your programs, use the SYMBOLGEN option or the %PUT statement to see what value replaces your macro variable references. You can use the %SYMDEL statement to remove macro variables from the global symbol table.

SYMBOLGEN Option Syntax

Use the SYMBOLGEN system option to monitor the value that is substituted for a macro variable reference.
Syntax, OPTIONS statement with the SYMBOLGEN option:
OPTIONS NOSYMBOLGEN | SYMBOLGEN ;
NOSYMBOLGEN
specifies that log messages about macro variable references will not be displayed. This is the default.
SYMBOLGEN
specifies that log messages about macro variable references will be displayed.
When the SYMBOLGEN option is turned on, SAS writes a message to the log for each macro variable that is referenced in your program. The message states the macro variable name and the resolved value.
Note: The SYMBOLGEN system option remains in effect until you modify it or until you end your SAS session.

Example: Using the SYMBOLGEN Option

Use the SYMBOLGEN option to view the results of the resolving macro variable references in the SAS log.
options symbolgen;
%let CarType=Wagon;
proc print data=sashelp.cars;
   var Make Model Type MSRP;
   where Type="&CarType";
run;
options nosymbolgen;
The SAS log shows the messages that are generated by the SYMBOLGEN option.
Log 7.1 SAS Log
SYMBOLGEN:  Macro variable CARTYPE resolves to Wagon

%PUT Statement Syntax

Use the %PUT statement to write your own messages to the SAS log.
Syntax, %PUT statement:
%PUT text;
text
is any text string.
Here is a quick description of the %PUT statement:
  • writes only to the SAS log
  • always writes to a new log line, starting in column one
  • writes a blank line if text is not specified
  • does not require quotation marks around text
  • resolves macro triggers in text before text is written
  • removes leading and trailing blanks from text unless a macro quoting function is used
  • wraps lines when the length of text is greater than the current line size setting
  • can be used either inside or outside a macro definition

Example: Using the %PUT Statement

Suppose you want to verify the value of the macro variable CarType. Since the %PUT statement resolves macro references in text before writing text to the SAS log, you can use it to show the stored value of CarType.
%put The value of the macro variable CarType is: &CarType
Log 7.2 SAS Log
119  %put The value of the macro variable CarType is: &CarType
The value of the macro variable CarType is: Wagon
You can also submit the statement %put &=cartype; This writes the macro variable name and its value in the log as follows:
Log 7.3 SAS Log
CARTYPE=SEDAN
The %PUT statement has several optional arguments.
Argument
Result in the SAS Log
_ALL_
lists the values of all macro variables
_AUTOMATIC_
lists the values of all automatic macro variables
_GLOBAL_
lists user-generated global macro variables
_LOCAL_
lists user-generated local macro variables
_USER_
lists the values of all user-defined macro variables
Note: When you use optional arguments such as _ALL_, each macro variable name is also written to the SAS log, along with a label of either AUTOMATIC or GLOBAL.

The %SYMDEL Statement

A Brief Overview

The %SYMDEL statement deletes the specified variables from the macro global symbol table. It also issues a warning when an attempt is made to delete a non-existent macro variable. To suppress this message, use the NOWARN option.

%SYMDEL Syntax

Syntax, %SYMDEL statement:
%SYMDELmacro-variable-1<...macro-variable-n></option>;
macro-variable
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 %SYMDEL statement.
option
NOWARN
suppresses the warning message when an attempt is made to delete a non-existent macro variable.

Example: Using the %SYMDEL Statement

The following example illustrates how the %SYMDEL statement deletes the listed variables from the global symbol table and releases memory back to the system.
%symdel CarType;
Nothing is written to the SAS log when the statement is executed.
Output 7.2 Global Symbol Table
Global Symbol Table
Last updated: October 16, 2019
..................Content has been hidden....................

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