You can store text
that is generated by the macro facility during macro execution in
an external file. Printing the statements generated during macro execution
to a file is useful for debugging macros when you want to test generated
text in a later SAS session.
To use this feature,
set both the MFILE and MPRINT system options on. Also assign MPRINT
as the fileref for the file to contain the output generated by the
macro facility:
options mprint mfile;
filename mprint 'external-file';
The external file created
by the MPRINT system option remains open until the SAS session terminates.
The MPRINT text generated by the macro facility is written to the
log during the SAS session and to the external file when the session
ends. The text consists of program statements generated during macro
execution with macro variable references and macro expressions resolved.
Only statements generated by the macro are stored in the external
file. Any program statements outside the macro are not written to
the external file. Each statement begins on a new line with one space
separating words. The text is stored in the external file without
the
MPRINT(macroname
: prefix, which is displayed in the log.
If MPRINT is not assigned
as a fileref or if the file cannot be accessed, warnings are written
to the log and MFILE is turned off. To use the feature again, you
must specify MFILE again.
By default, the MPRINT
and MFILE options are off.
The following example
uses the MPRINT and MFILE options to store generated text in the external
file named TEMPOUT:
options mprint mfile;
filename mprint 'TEMPOUT';
%macro temp;
data one;
%do i=1 %to 3;
x&i=&i;
%end;
run;
%mend temp;
%temp
The macro facility writes
the following lines to the SAS log and creates the external file named
TEMPOUT:
MPRINT(TEMP): DATA ONE;
NOTE: The macro generated output from MPRINT will also be written
to external file '/u/local/abcdef/TEMPOUT' while OPTIONS
MPRINT and MFILE are set.
MPRINT(TEMP): X1=1;
MPRINT(TEMP): X2=2;
MPRINT(TEMP): X3=3;
MPRINT(TEMP): RUN;
When the SAS session
ends, the file TEMPOUT contains:
DATA ONE;
X1=1;
X2=2;
X3=3;
RUN;
Note: Using MPRINT to write code
to an external file is a debugging tool only. It should not be used
to create SAS code files for purposes other than debugging.