- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%* 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;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does the documentation tell you how such a comment needs to be terminated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Comparison of the different comment syntax here:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%macro test;
%put a;
*%put b;
%*put c;
/*%put d;*/
%put abcd;
%mend test;
%test;