BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GeorgeSAS
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

11 REPLIES 11
PaigeMiller
Diamond | Level 26

%* 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
GeorgeSAS
Lapis Lazuli | Level 10
How about *%testA;?

Thanks
Patrick
Opal | Level 21

@GeorgeSAS

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

art297
Opal | Level 21

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

 

PaigeMiller
Diamond | Level 26

@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
GeorgeSAS
Lapis Lazuli | Level 10

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

art297
Opal | Level 21

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

ballardw
Super User

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

Tom
Super User Tom
Super User

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.

 

GeorgeSAS
Lapis Lazuli | Level 10
Thank you all!

%macro test;
%put a;
*%put b;
%*put c;
/*%put d;*/
%put abcd;
%mend test;
%test;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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