Hi folks,
I ran into this user's problem today: https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-comment-in-a-macro-why-after-40-years...
TL;DR: I got the following error when attempting to run a large block of code encompassed within a macro because I put an apostrophe (I used the word "it's"...) in one of my comments within that block of code: "The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation marks."
I certainly didn't have reason to be as miffed as the user referenced in the link above (I only wasted about half an hour or so...), but I was wondering what the pitfalls were of just always enclosing comments with /*comment*/, particularly within a block of code encompassed within a macro, in order to avoid this issue. I'm not a seasoned SAS programmer by any means, so I know there are some things I'm not thinking of.
Thanks!
This is a useful explanation of comments inside macros.
Depends on how you code. Take this program:
data a;
x=5; /* set x to 5 */
y=3;
run;
And imagine that it were a lot larger and more complicated.
Now, you want to temporarily remove some line(s) of code from the program, so you do this:
data a;
/*
x=5; /* set x to 5 */
*/
y=3;
run;
(in the example, we now only want the Y variable). But this last bit of code will not work as intended, as SAS does not understand nested comments. So the code between DATA and RUN will be interpreted as two comments, the first is
/*
x=5; /* set x to 5 */
and the second is an asterix-type comment
*/
y=3;
Meaning that using "*" and "%*" comments inside the code can make it a lot easier to comment out unneeded code.
But you are right, there are also problems with that comment style, e.g. yours with the unmatched quotes. So it becomes a matter of preferences and convenience, until (perhaps) SAS some day starts supporting nested /*...*/ comments.
Yes--I've had that issue with nested comments before 😕
The following worked for me now for many years:
The only two cases I'm aware of where you have to be watchful using /*....*/
Thanks! I didn't consider the "%macro null; [...] %mend;" option. Might use that for the application you're describing here.
With SAS on a Mainframe (z-OS) don't start /* on the first column as this means "end of program" and nothing below will execute.
That's only when you put the code right into the JCL, using "//SYSIN DD *". If you put your program in another dataset or member, e.g. "//SYSIN DD DSN=ASF13.DIV.SASPROG(PROG1)", you will not have that problem.
I think /* comments are generally a good idea. I tend to use a mix of * comments and /* comments. And I basically avoid typing apostrophes into comments (even though they are 'safe' in /* comments, I feel like avoiding unmatched quotes in comments is a good 'rule'.
One factor to consider in deciding for * vs /* comments in a macro setting is whether you want the comment to be seen in the log when the macro executes (assuming MPRINT is turned on).
If you use a * comment in a macro, the macro language will generate the * comment when the macro executes (because * is not a comment in the macro language):
If you use a /* comment in a macro (or a %* comment), it is a macro language comment, and will not be generated when the macro executes.
1 %macro test1() ; 2 data want ; 3 x=1 ; *Show this comment in MPRINT ; 4 run ; 5 %mend ; 6 7 %test1() MPRINT(TEST1): data want ; MPRINT(TEST1): x=1 ; MPRINT(TEST1): *Show this comment in MPRINT ; MPRINT(TEST1): run ; NOTE: The data set WORK.WANT has 1 observations and 1 variables. 8 9 %macro test2() ; 10 data want ; 11 x=1 ; /*Do not show this comment in MPRINT */ 12 run ; 13 %mend ; 14 15 %test2() MPRINT(TEST2): data want ; MPRINT(TEST2): x=1 ; MPRINT(TEST2): run ; NOTE: The data set WORK.WANT has 1 observations and 1 variables.
Thanks for the detailed response!
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.