Displaying Macro Variable Values in the SAS Log

The SYMBOLGEN Option

When you submit a macro variable reference, the macro processor resolves the reference and passes the value directly back to the input stack. Therefore, you do not see the value that the compiler receives. In order to debug your programs, it might be useful for you to see the value that replaces your macro variable reference. You can use the SYMBOLGEN system option to monitor the value that is substituted for a macro variable reference.
General form, OPTIONS statement with SYMBOLGEN option:
OPTIONS NOSYMBOLGEN | SYMBOLGEN;
Here is an explanation of the syntax:
NOSYMBOLGEN
specifies that log messages about macro variable references are not displayed. This is the default.
SYMBOLGEN
specifies that log messages about macro variable references are displayed.
This system option displays the results of resolving macro variable references in the SAS log. That is, 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: Remember that since SYMBOLGEN is a system option, its setting remains in effect until you modify it or until you end your SAS session.

Example

Suppose you have previously assigned values to the macro variables amount, city, and company, and you submit the following code:
data new;
   set sasuser.all;
   where fee>&amount;
   where also city_state contains "&city";
   where also student_company contains '&company';
run;
Here is a sample SAS log that shows the messages that are generated by the SYMBOLGEN option for this code. The WHERE ALSO conditions augment the initial WHERE condition using the AND operator. In this example, the where processing is done for the following condition: (fee>&amount) AND (city_state contains "&city") AND (student_company contains '&company').
Table 9.2 SAS Log
110 where fee>&amount;
SYMBOLGEN: Macro variable AMOUNT resolves to 975
111 where city_state contains "&city";
SYMBOLGEN: Macro variable CITY resolves to Dallas
112 where student_company contains '&company';
Notice that no message is displayed for the final macro variable reference ('&company'). Because this macro variable reference is enclosed in single quotation marks rather than in double quotation marks, the word scanner does not call the macro facility to resolve it.

The %PUT Statement

Another way of verifying the values of macro variables is to write your own messages to the SAS log. The %PUT statement writes text to the SAS log.
General form, basic %PUT statement:
%PUT text;
Here is an explanation of the syntax:
text
is any text string.
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

Suppose you want to verify the value of the macro variable city. 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 city.
%put The value of the macro variable CITY is: &city;
Table 9.3 SAS Log
120 %put The value of the macro variable CITY is: &city;
The value of the macro variable CITY is: Dallas
You can also simply submit the statement &put &city; without any additional text. This statement writes the resolved value of the macro variable city to the SAS log. However, it does not write any additional text to the log. You might find that it is a good idea to add explanatory text to your %PUT statements in order to maintain clarity in the SAS log. The %PUT statement has several optional arguments that you can add.
Argument
Result in SAS Log
_ALL_
Lists the values of all macro variables
_AUTOMATIC_
Lists the values of all automatic macro variables
_LOCAL_
Lists user-generated local macro variables
_USER_
Lists the values of all user-defined macro variables
Table 9.4 SAS Log
121 %let year=2002;
122 %let city=New York;
123 %let region=South;
124 %put _all_;
GLOBAL YEAR 2002
GLOBAL REGION South
GLOBAL CITY New York
AUTOMATIC AFDSID 0
AUTOMATIC AFDSNAME
AUTOMATIC AFLIB
AUTOMATIC AFSTR1
AUTOMATIC AFSTR2
AUTOMATIC FSPBDV
AUTOMATIC SYSBUFFR
AUTOMATIC SYSCC 0
AUTOMATIC SYSCHARWIDTH 1
AUTOMATIC SYSCMD
AUTOMATIC SYSDATE 29MAY02
Notice that 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.
..................Content has been hidden....................

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