Hello,
When I trying to comment out a macro, do I use *% or %*? what difference?
Thanks!
%macro testA;
*......;
%mend testA;
%*testA;
*%testA;
I hope my question is clear, if not. please let me rephrase it:
%testA is a user defined macro.
I don't want it be executed, so I add a '*'
*%testA;
My question is how it compare with %*testA?
Looks either way will not execute the macro(all works).
If you have a program that is calling a macro like it was a statement with a teminating semi-colon.
%mymacro(...);
If you insert an * before the statement then it will look like a comment statement. And if you insert the * after the % then it will look like a macro comment statement. In open code either method will work.
But inside of another macro definition only the macro comment will work. The comment statement is no different to the macro processor than any other SAS statement that the macro is generating. So it will generate the code that the %mymacro() call generates and the first SAS statement in the resulting code will become a comment since it now starts with * that preceeded in it.
And if your macro call does not have a semi-colon after it then you also need to make sure to add one or else the next statment will become part of the comment.
%* is a macro comment
/* and */ also works for me
You could also give the macro some name that won't ever be called (easy enough to change it back if you decide you want the macro). For example,
%macro dont_do_this;
...
%mend;
What does the documentation tell you how such a comment needs to be terminated?
NO! * will most often NOT work to comment out code in a macro, only %* and the /* */ combination.
One always can run into a problem is trying to comment out code that already has code commented statements imbedded in it. For that, as far as I know, there isn't a readily available method.
Art, CEO, AnalystFinder.com
@art297 wrote:
One always can run into a problem is trying to comment out code that already has code commented statements imbedded in it. For that, as far as I know, there isn't a readily available method.
The method to comment out code that has commented statements embedded into it:
inside a macro, use:
%if 0 %then %do;
...
%end;
If not inside a macro, then you can comment out this section by making it a macro that is never called:
%macro dont_do_this;
...
%mend;
Naturally, you might want to add a comment statement just before you do this explaining that you are commenting out a whole block of code.
Comparison of the different comment syntax here:
I hope my question is clear, if not. please let me rephrase it:
%testA is a user defined macro.
I don't want it be executed, so I add a '*'
*%testA;
My question is how it compare with %*testA?
Looks either way will not execute the macro(all works).
As long as it isn't being called from within a macro, then *%testA; should work as well as /* */.
I've never used the macro style comment (*%) outside of macros, but presume it would work.
Art, CEO, AnalystFinder.com
Context of where the code you comment can make a difference.
I fought briefly with this many years ago and settled on ALWAYS using the /* */.
For one thing that style can be used in the middle of statement such as
data junk;
set morejunk (keep= thisvar var10 thatvar /* tempvar*/ );
which neither of *; or %*; will do and the /* */ works inside macros as well.
And with the enhanced editor having the Ctrl-/ key stroke to comment entire blocks lines and Shift-Ctrl-/ to uncomment it isn't much additional work. (though you do have to be very careful and not nest creating /* /* */ */ comments).
If you have a program that is calling a macro like it was a statement with a teminating semi-colon.
%mymacro(...);
If you insert an * before the statement then it will look like a comment statement. And if you insert the * after the % then it will look like a macro comment statement. In open code either method will work.
But inside of another macro definition only the macro comment will work. The comment statement is no different to the macro processor than any other SAS statement that the macro is generating. So it will generate the code that the %mymacro() call generates and the first SAS statement in the resulting code will become a comment since it now starts with * that preceeded in it.
And if your macro call does not have a semi-colon after it then you also need to make sure to add one or else the next statment will become part of the comment.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.