Macro resolution tracking

In the preceding example, we are able to create the New dataset when we run the macro definitions. However, the value of the macro variable isn't written to the log. This was an instance of a single macro variable. Most macros in real life may contain multiple nested macros, with many macro variables in each nested macro. In such a situation, it is helpful to know what the resolution of the macro variable is. Adding a %PUT statement can be very helpful:

%Let File = Class;

Data New;
Set &File;
New_Weight=Weight*1.1;
Run;

%PUT The resolution of macro variable File is &File;
The %PUT statement helps write the resolution of the macro variable File to the LOG. Below is the message in the LOG.

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NEW has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

79
80 %PUT The resolution of macro variable File is &File;
The resolution of macro variable File is Class

The %PUT statement does not need to be part of the DATA or PROC step. It is useful for only displaying the resolution of macro variables in LOG. Along with %PUT, the following options are also useful:

OPTION

PURPOSE

_ALL_

Helps list all macro variables

_AUTOMATIC_

Lists all automatic macro variables

_GLOBAL_

Lists all user-defined global macro variables

_LOCAL_

Lists all user-defined local macro variables defined within the currently executing macro

_USER_

Lists all user-defined macro variables

 

Let's also explore a few other options, such as MLOGIC, MPRINT and SYMBOLGEN.

 

We will invoke the demo macro that we compiled earlier and study LOG:

Options MLOGIC;
%demo(File=Class);

The LOG produced is below.

75 %demo(File=Class);
MLOGIC(DEMO): Beginning execution.
MLOGIC(DEMO): Parameter FILE has value Class

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NEW has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


MLOGIC(DEMO): Ending execution.

Instead of writing a %PUT statement, it may be beneficial to use the MLOGIC option when trying to resolve multiple macro variables. The MLOGIC option has written the value of the FILE parameter to LOG. The MLOGIC resolution is already prefixed with the word MLOGIC word in LOG. If MLOGIC is in effect and the macro processor encounters a macro invocation, the macro processor displays messages that identify the following:

The MLOGIC option writes the macro resolution in LOG. The MPRINT option goes a bit further and substitutes the macro variable in the program with the values that get assigned to the macro variable:

Options MPRINT;
%demo(File=Class);

MPRINT(DEMO): Data New;
MPRINT(DEMO): Set SASHELP.Class;
MPRINT(DEMO): New_Weight=Weight*1.1;
MPRINT(DEMO): Run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NEW has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

As you can see, the &File syntax has been replaced by the CLASS filename after the resolution of the macro variable.

If you are looking for a separate statement about the macro variables result then MLOGIC is best suited. Otherwise, try to use the MPRINT option:

Options SYMBLOGEN;
%demo(File=Class);

SYMBOLGEN: Macro variable _SASWSTEMP_ resolves to /folders/myfolders/.sasstudio/.images/e67748fb-709a-4652-bc7f-e969ca8431d8
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN: Macro variable GRAPHINIT resolves to
72
73 Options SYMBOLGEN;
74
75 %demo(File=Class);
SYMBOLGEN: Macro variable FILE resolves to Class

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NEW has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

76
77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
SYMBOLGEN: Macro variable GRAPHTERM resolves to
89

The SYMBOLGEN system option tells you what each macro variable resolves to by writing messages to the SAS log. This option is especially useful in spotting quoting problems, where the macro variable resolves to something other than what you intended because of a special character. It is also useful for decoding macro variables specified by a double ampersand (&&).

It is, at times, handy to store the macro variable resolution to an external file. You can store the output of MPRINT in an external file. The statements needed to store it are as follows:

options mprint mfile;
filename mprint 'TEMPOUT';

Please use this with caution—your SAS version and system access limitations may disallow storing of files to your chosen location.