BookmarkSubscribeRSS Feed

This would allow code like

 

%if &i=1  ## comment 1

  | &i=2  ## comment 2

  | &i=3  ## comment 3

%then %let i=4;

 

The only method for these comments atm is to use /* */ comments, which I avoid as I reserve /* */  to comment out large blocks of text on an ad-hoc basis (debugging, rerunning parts of a program).

 

And of course blocks of text cannot be commented out if they contain /* */ comments themselves. If they do, the only way to comment them out if to enclose them in dummy macros, which can cause other issues.

 

[Edit: Replaced // with ## in my example, as // is commonly used to skip lines in put statements.

I don't mind what characters are used.]

 

15 Comments
Kurt_Bremser
Super User

Like that idea. I often would like to have an option to insert comments inline within a statement (eg an if) without losing the option to out-comment whole sections of code with /* */.

Astounding
PROC Star

Don't forget that // already has meaning within a PUT or INPUT statement:  skip 2 lines before continuing.  In its current form, your suggestion might affect many existing programs.

ChrisHemedinger
Community Manager

The idea appeals to me too -- as I often enter a "//" comment on a SAS program and then the color-coding editor reminds me that it doesn't make sense...  But that's more about my habit from using other programming languages, and not a desire to have line-ending comments like @ChrisNZ describes.

 

As @Astounding says, I think that this would be tricky (if not impossible) to implement due to reserved operators in the bowels of the SAS language.  Today:

 

comment This is a comment;
* so is this;
/* and of course, so is this */
%* and don't forget macro comments that get stored INSIDE the compiled macro;

I'm sure @ChrisNZ knows this, but for others: don't forget that in SAS or SAS Enterprise Guide program editor, the Ctrl+/  and Shift+Ctrl+/ keys can toggle the block-style comments (/* */) for the selected text.

 

commenting.gif

ballardw
Super User

Minor correction on Chris's comment for Ctrl+/ , it selects the entire line regardless of selected text.

And if the block comment does not include the entire line then Shift+Ctrl+/ does nothing.

 

One of the reasons I used the IBM EPM editor when I was programming on a OS/2 machine with version 6 was the ability to have an actual block comment, highlight sections of text in a rectangle and comment just that.

 

 

About the // for comments: I'm not sure that the saving of 2 chacters for a comment is worth the complexity of something without an ending character. * ;  comment END with ; /* */ ENDS with */ A // that has no end in the middle of code seems our of style with general SAS coding behavior.

ChrisNZ
Tourmaline | Level 20

 

Thank you all for your interest and thoughtful comments. 🙂

 

@ballardw Many languages with en ending character, including a semicolon, use // comments.

 

@Astounding Mmm good point. I forgot about these. I guess we'd need an option to disable/enable // comments.

 

@ChrisHemedinger Kudos on the animated gif! I like the dedication to good comunication. 🙂

As for being tricky because of other constructs, I respectfully disagree. // tells the parser: move along nothing to see here, the end of the line is here, consider the rest of the line as empty.

Tom
Super User
Super User

I cannot see how this can be supported without massive changes to the meaning of existing code. The most obvious example is the PUT statement.  What if I have a program that wants to write multiple lines and currently uses // to insert two line breaks?

 

put 'Line one' // 'Line three';

What if you had a  macro variable with a delimited list of words separated by / and you wanted to represent a missing value?

 

%let x=a//c;
%let y=%sysfunc(tranwrd(&x,//,/./));

 

Also with this style of comment the end-of-line becomes part of the syntax of the language.  Previously that was only true for in stream data.  (What happens if you have // in your in stream data?)

 

What would happen if you used these in a macro definition? Would these comments appear when you turned on the MPRINT option?  What about inside of text sent to be processed by CALL EXECUTE commands?

 

Personally I find end of line comments hard to read and a pain in the neck to maintain. Plus by the time you get to them it is too late, you have already seen the code.  You should put the comments that explain your code before the code.  

ChrisNZ
Tourmaline | Level 20

Yes, Tom all good points and questions.

 

You can always write

put 'Line one' / / 'Line three';

of course but legacy is an issue,

 

>What would happen if you used these in a macro definition?

In the unlikely case this was necessary, nothing would happen
%macro foo(param1=%str(/)*       // this parameter is required

                   ,param2=%str(/)/       // this parameter is optional

                   );

 

>Would these comments appear when you turned on the MPRINT option?

Either way is fine

 

>What about inside of text sent to be processed by CALL EXECUTE commands?

As each call execute generates a line of code, the treatment would be the very same as regular lines of code, if such comments were ever generated in this context.

 

 >PS What happens if you have // in your in stream data?
The code parser doesn't look at data streams. Is /* an issue as part of the data?

 

An option to allow // comments or not, like the minoperator option which also came to allow progress while preserving compatibility, would allay these concerns.

We could also consider for example ~~ comments if // appears to be too much of an issue, but why be different?

 

 

ChrisNZ
Tourmaline | Level 20

 

Just reviving this as I still would very much like this feature, and the discussion focused on the slashes (my fault for including them in the title)

 

Since // is an issue, maybe some other characters could be used, like ## or ~~ or anything else that does the job.

 

 

jimbarbour
Meteorite | Level 14

If // were such an issue (and it does appear to be), what about two left slanting single quotes (``)?  I see newer DBMS code taking advantage of a left slanting single quote.  Newer key boards seem to have the character.  On an older keyboard, one would be no worse of than they are now.

 

Jim

emacklin
Calcite | Level 5

I share the commenters enthusiasm for a syntax that would permit in-line comments (implicitly terminated at a newline) that isn't /**/.  I similarly avoid /**/ comment blocks given their potential for breaking wrapper code that might call a given program via an %include statement.  When I really want to comment in-line, usually to comment within a block of SQL code, I lean on a trick of using %sysfunc to execute functions at (nearly) any location.  See the example below (and note the feedback provided in the log that PROC SQL is blind to the comment).

 

proc sql feedback;
  create table work.class as 
    select *  
         , (Age    - median(Age   )) as cAge    %sysfunc(ifc(0, 'See notes from 2023-05-13 meeting to center on median rather than mean age',,)) 
         , (Height - mean  (Height)) as cHeight 
         , (Weight - mean  (Weight)) as cWeight 
    from sashelp.class 
    group by Sex 
    order by Name;
quit;

Hope folks find that helpful.