DATA Step, Macro, Functions and more

comment out a macro

Accepted Solution Solved
Reply
Regular Contributor
Posts: 241
Accepted Solution

comment out a macro

[ Edited ]

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
Solution
‎06-07-2017 12:07 PM
Super User
Super User
Posts: 7,074

Re: comment out a macro

Posted in reply to GeorgeSAS

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.

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,931

Re: comment out a macro

Posted in reply to GeorgeSAS

%* 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;

Regular Contributor
Posts: 241

Re: comment out a macro

Posted in reply to PaigeMiller
How about *%testA;?

Thanks
Respected Advisor
Posts: 4,173

Re: comment out a macro

[ Edited ]
Posted in reply to GeorgeSAS

@GeorgeSAS

What does the documentation tell you how such a comment needs to be terminated?

PROC Star
Posts: 7,487

Re: comment out a macro

Posted in reply to GeorgeSAS

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

 

Trusted Advisor
Posts: 1,931

Re: comment out a macro


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.

Respected Advisor
Posts: 4,173

Re: comment out a macro

Posted in reply to GeorgeSAS
Regular Contributor
Posts: 241

Re: comment out a macro

[ Edited ]
Posted in reply to GeorgeSAS

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).

PROC Star
Posts: 7,487

Re: comment out a macro

Posted in reply to GeorgeSAS

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

Super User
Posts: 11,343

Re: comment out a macro

Posted in reply to GeorgeSAS

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).

Solution
‎06-07-2017 12:07 PM
Super User
Super User
Posts: 7,074

Re: comment out a macro

Posted in reply to GeorgeSAS

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.

 

Regular Contributor
Posts: 241

Re: comment out a macro

Thank you all!

%macro test;
%put a;
*%put b;
%*put c;
/*%put d;*/
%put abcd;
%mend test;
%test;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 327 views
  • 4 likes
  • 6 in conversation