News / Features

News

 

Macro malfunction or user error? 

Warren Repole, a Training Specialist with SAS Education and Training, helps answer questions that students pose to instructors through SAS' instructor list serve. Recently, Repole received this question from a SAS® user who was attending a training class:

SAS User: Under what circumstances would a comment in the form * add_comment_here; cause undesirable results?

Repole: The big problem with the *comment; form is that folks tend to use it (improperly) to comment out macro statements such as %LET or %PUT. This works in open code but not within a macro, evidence that differences in how the tokens are processed depends on the context.

So it's not really a software issue; it's primarily a "user error" issue.

Here is a common example:
Despite attempting to comment out the %PUT statement within the macro, the %PUT executes anyway. More importantly, notice the code generated by MPRINT. The wrong statement was commented out.

Yikes!

1          options nostimer;
2   
3          *%put NOTE: Today is &sysdate9;
4          proc print data=sashelp.class;
5          run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS
NOTE: The PROCEDURE PRINT printed page 1.


7          %macro mymacro;
8            *%put NOTE: Today is &sysdate9;
9            proc print data=sashelp.class;
10           run;
11         %mend mymacro;
12         options mprint;
13         %mymacro

NOTE: Today is 05MAY2009
MPRINT(MYMACRO):   * proc print data=sashelp.class;
MPRINT(MYMACRO):   run;

[You may recognize that the NOSTIMER option serves no other purpose than to remove some extraneous information from the SAS log, making it easier to read.]