Published on :

SAS Macro Compilation and Usage with MCOMPILENOTE

This code is also available in: Deutsch Español Français
The script begins with a detailed explanation of SAS© macro compilation, emphasizing that the macro processor checks the syntax of macro statements and stores the compiled definition in a temporary SAS© catalog (usually `work.sasmacr`). It highlights the importance of the `MCOMPILENOTE=ALL` option for confirming successful compilation and obtaining information about the macro (number of statements, size) in the SAS© log. The `prtlast` macro is provided as a practical example, using `PROC PRINT` to display the first 10 rows of the last SAS© table (`&syslast`) in the session.
Data Analysis

Type : INTERNAL


The code uses the automatic macro variable `&syslast` which references the last SAS table created or modified in the current session. The data therefore comes from the SAS session itself, not from an external source or created directly by this script.

1 Code Block
OPTION
Explanation :
This SAS statement activates the `MCOMPILENOTE=ALL` system option. This configures SAS to issue a note in the log each time a macro is compiled, indicating the success of the compilation, the number of statements, and the size of the macro.
Copied!
1options mcompilenote = all;
2 Code Block
MACRO DEFINITION (%prtlast)
Explanation :
This block defines a SAS macro named `prtlast`. When executed, this macro uses `PROC PRINT` to display the first ten observations (`obs=10`) of the last SAS table created or modified in the session (`&syslast`). A dynamic title is also applied to the listing, including the name of the table being processed.
Copied!
1 %macro prtlast;
2 PROC PRINT DATA=&syslast (obs=10);
3 title "Listing of &syslast data set";
4 RUN;
5 %mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.