Debugging Macros

The MPRINT System Option

A Brief Overview

The MPRINT system option displays the text generated by macro execution. Each SAS statement begins a new line. Each line of MPRINT output is identified with the prefix MPRINT(macro-name), to identify the macro that generates the statement.
You can direct MPRINT output to an external file by also using the MFILE option and assigning the fileref MPRINT to that file.
You might want to specify the MPRINT system option under these conditions:
  • You have a SAS syntax error or execution error.
  • You want to see the generated SAS code.
The MPRINT system option is often synchronized with the SOURCE system option to show, or hide, executed SAS code.

The MPRINT Option Syntax

Syntax, MPRINT system option:
MPRINT | NOMPRINT;
MPRINT
displays the SAS statements that are generated by macro execution. The SAS statements are useful for debugging macros.
NOMPRINT
does not display SAS statements that are generated by macro execution.

Example: Using the MPRINT Option

Suppose you want to call the Prtlast macro and use the MPRINT system option to show the SAS code that results from the macro execution.
Catalog Entry
%macro prtlast;
   proc print data=&syslast (obs=5);
      title "Listing of &syslast data set";
   run;
%mend prtlast;
The following sample code creates a data set named Sales, specifies the MPRINT system option, and references the Prtlast macro:
data sales;
   price_code=1;
run;
options mprint;
%prtlast
The messages that are written to the SAS log show the text that is sent to the compiler. Notice that the macro variable reference (&SYSLAST) is resolved to the value Work.Sales in the MPRINT messages that are written to the SAS log.
Log 9.4 SAS Log
101  %prtlast
MPRINT(PRTLAST): proc print data=WORK.SALES (obs=5);
MPRINT(PRTLAST): title "Listing of WORK.SALES";
MPRINT(PRTLAST): run;
NOTE: There were 1 observations read from the dataset WORK.SALES.
NOTE: PROCEDURE PRINT used:
      real time           0.04 seconds
      cpu time            0.04 seconds

Comments in Macro Programs

A Brief Overview

The macro comment statement is useful for describing macro code. Text from a macro comment statement is not constant text and is not stored in a compiled macro. Because a semicolon ends the comment statement, the comment cannot contain internal semicolons unless the internal semicolons are enclosed in quotation marks or a macro quoting function. Macro comments are not recognized when they are enclosed in quotation marks.
Quotation marks within a macro comment must match.

Comment Statement Syntax

Syntax, macro comment statement:
/*comment*/;
comment
can be any message. Like other SAS statements, each macro comment statement ends with a semicolon.

Example: Use Macro Comments

The following code uses macro comments to describe the functionality of the macro:
%macro printit;
   /*The value of &syslast will be substituted appropriately*/
   /* as long as a data set has been created during this session.*/
   proc print data=&syslast(obs=5);
/* Print only the first 5 observations */
   title "Last Created Data Set Is &syslast";
   run;
%mend;
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.12.164.101