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
Tom
Super User
Super User

I just want to repeat my earlier point:

 

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. 

If you want to add comments to your code put them BEFORE the code so the reader can use that knowledge to decide whether to skip over the details of the code.

 

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

 

Rapson
Calcite | Level 5

I use /* */ for end of line comments.

I use *; for full line comments.

I use %macro skip; A bunch of text or code I want to comment out. %mend skip; for large blocks of comments and code. It is more reliable.

 

Of course, I also write 90% in SQL so any in-code comments have to be /* */ for cross-functionality in implicit and explicit code. The downside is that often CTRL+/ is useless. I would vote for //* *// (or something similar) for auto comment. 

Quentin
Super User

@emacklin, wouldn't it be easier to use macro language %* comment, e.g.:

 

proc sql feedback;
  create table work.class as 
    select *  
         , (Age    - median(Age   )) as cAge    %* 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;

data want ; 
  set sashelp.class ;
  if Sex="M" %* comment 1 ;
   | Sex="F" %* comment 2 ;
  then SexFlag=1 ;
run ;

 

@ChrisNZ  given the availability of #* comments, which I think will work as a mid-statement  comment anywhere in SAS  except the macro language, is this suggestion specific to wanting a mid-statement comment for the macro language?  

ChrisNZ
Tourmaline | Level 20

given the availability of #* comments, which I think will work as a mid-statement comment

You mean %* comments?

I only use these except for file headers. But:

1. After decades being there, the colour parser still can't colour these properly

2. After decades being there, the interpreter still can't parse these properly if they include a quote

3. Yes, unusable inside macro statements

4. Needing a closing ; is an additional constraint

 

 

 

Quentin
Super User

Indeed, I meant %* comments.

 

I don't see how SAS could get away from using a semicolon, or some other token, to end the comment.  If you don't have an ending token, SAS would need to use the end of the line terminator (CR/LF/etc) to end the comment.  But of course  in SAS the line terminator has no meaning (currently), outside of CARDS / DATALINES.  And we know the macro processor doesn't preserve line terminators, which is why CARDS can't be used inside a macro.  So if you had a  comment token which used the line terminator to indicate the end of the comment, my guess is those comments wouldn't work when used inside a macro.

 

It would be nice if %* could hide  a single quote.  I would definitely upvote that.  For years, I've just had the rule of not using apostrophes in comments.