BookmarkSubscribeRSS Feed
0 Likes

Below code submitted in EG 6.1 but I suspect it's applicable in DMS, Studio, etc.

 

Below are test scenarios based on a comment in my actual code (the 2nd comment is just to generate 262 characters)

 

 

* Workaround SAS's inability to include the datalines statement inside a macro ;

/*
This is a really long comment to generate 262 characters after the single quotation mark.
I sure wish the macro compiler could treat a single quote within a comment as just that,
a comment, instead of treating the single quote as a special character.
It works with slash-asterisk style commenting but not other commenting styles.
*/

data foo;x=1;run;

 

 

Submit this...so far, so good.

 

 

%* Workaround SAS's inability to include the datalines statement inside a macro ;

/*
This is a really long comment to generate 262 characters after the single quotation mark.
I sure wish the macro compiler could treat a single quote within a comment as just that,
a comment, instead of treating the single quote as a special character.
It works with slash-asterisk style commenting but not other commenting styles.
*/

data foo;x=1;run;

 

 

Submit this...oops.

 

But at least submitting ;*';*";*/;quit;run; fixes the issue.

 

 

But now I want to comment out the entire code block.  So I use the "trick" of wrapping the code in an uncalled comment block:

 

 

%macro comment;
* Workaround SAS's inability to include the datalines statement inside a macro ;

/*
This is a really long comment to generate 262 characters after the single quotation mark.
I sure wish the macro compiler could treat a single quote within a comment as just that,
a comment, instead of treating the single quote as a special character.
It works with slash-asterisk style commenting but not other commenting styles.
*/

data foo;x=1;run;
%mend comment;

 

 

Submit this...oops again.

 

At this point, submitting ;*';*";*/;quit;run; doesn't work, nor does %mend;;*';*";*/;quit;run;  

 

At this point all I know to do is restart the workspace server.

 

However, submit this:

 

%macro comment;
/* Workaround SAS's inability to include the datalines statement inside a macro */

/* 
This is a really long comment to generate 262 characters after the single quotation mark.
I sure wish the macro compiler could treat a single quote within a comment as just that, 
a comment, instead of treating the single quote as a special character.
It works with slash-asterisk style commenting but not other commenting styles.
*/

data foo;x=1;run;
%mend comment;

That works.

 

So, whatever the macro and/or SAS compiler is doing in this last example, do this for the previous examples as well.

 

If a statement is a comment, then the contents of the comment shouldn't "break SAS".

 

I suspect that this could be harder than it appears, and would require a lot of testing for backwards compatibility.  

 

But this issue bites me occasionally, when I forget and use a single quote in a comment, and in this case I lost a couple hours worth of WORK datasets when I had to restart the workspace server.

 

 

3 Comments
ballardw
Super User

If your first example is actually one line as it appears as posted in the forum I have little sympathy as that is way long for a single line of text.

 

In DM when I run

data dummy;
   * as single line comment with a ' embedded in it;/* This is a really long comment to generate 262 characters after the single quotation mark. I sure wish the macro compiler could treat a single quote within a comment as just that,  a comment, instead of treating the single quote as a special character.It works with slash-asterisk style commenting but not other commenting styles.*/

   set junk;
run;

I have no problem. So I am not sure what you may be attempting or where your problem is comming from.

 

It isn't clear if your problem involves the macro language or not. If so then a single comment *this comment; is not a good idea in general (the macro processor does not see it as comment per se). And I don't use the %* style of comment; and stick with /* style comments*/ every where just to simplify things.

ScottBass
Rhodochrosite | Level 12

"If your first example is actually one line as it appears as posted in the forum I have little sympathy as that is way long for a single line of text."

 

It's not, it's a shortcoming of the forum software.  I pasted some code edits inside the code tags, the code looked fine in the editor, but was reformatted when I posted.  Unlike other areas of the forum, I can't see a way to edit ballot ideas once they're posted.  So I have little sympathy for your smug comment.

 

"I have no problem. So I am not sure what you may be attempting or where your problem is comming (sic) from."

 

If you ran my tests as posted the issue would be obvious.

 

"If so then a single comment *this comment; is not a good idea in general (the macro processor does not see it as comment per se). And I don't use the %* style of comment; and stick with /* style comments*/ every where just to simplify things."

 

Good for you, I have a different coding style, and use all three forms of commenting.

 

Sure, "don't do that" to work around poor software design is one approach.  I prefer to offer suggestions on how the software could be improved.

Quentin
Super User

I think it's fair for * comments and %* comments to work differently.  The * commment is a comment in the SAS language, and the %* is a comment in the macro language.  Sometimes this difference is useful, for example a macro can generate * comments that will show up in the log as generated code when MPRINT is used.

 

So it doesn't bother me that a * comment that has an unmatched quote causes problems for the macro compiler, since it doesn't know about * comments.

 

But, it does bother me that unmatched  quotes inside of a %* comment cause a problem :

%macro comment;
%* Workaround SAS's blah;
%mend comment;

 

As I understand it, these cause a problem in part because %* comments are tokenized, while /* */ comments are not.  %* comments are also stored as part of the macro definition. 

 

I don't see a benefit to tokenizing %* comments.  I suppose some people might like that %* comments are stored as part of the macro definition, but it's not a benefit for my use of the macro language.  So I'd be happy to see %* comments treated the same as /* */ comments, if that were possible.

 

I've been bitten by this enough to avoid unmatched quotes in comments, because I assume any code/comment I write might eventually wind up in a macro.  But I agree, this is a workaround.  And when convering other people's code to  macros, there is always the risk that an apostrophe will sneak in.