Errors Thrown By SAS Macro Comments

sas
Author

TheCoatlessProfessor

Published

December 24, 2013

When working with SAS Macros, one of the most dastardly needs is to comment code. Easy no? Think again!

Let’s just start by using a traditional means of commenting the *; in OPEN CODE:

*%let some_variable = TOAD;

After running the declaration statement in open code, the prefix of the asterisk (*) to the %LET removes the assignment of TOAD to some_variable.

However, if we apply the same comment style (*some text to comment;) to code within a SAS Macro, then SAS goes,“Woaah Nellie! What is all this text!??!” SAS will effectively throw a hissy fit better than the average two year old.

options mprint mlogic mtrace symbolgen;
%macro random_macro();
*%let some_variable = TOAD;
%mend random_macro;
%random_macro();

But wait, why? Why is SAS acting like that? Examining the logs, the result of is an assignment of TOAD to some_variable and a RETURN from the macro function %random_macro of *

If the intent when coding is to use this similar style of comments within a macro function, then place the astrisks before a percentage sign like so:

%* This macro comment is processed aokay in macro functions unlike its predecessor.;

Some helpful tips for commenting: