Is this the fourth way to add comment text in SAS?

Viewed 1175

As far as I know, there are three kinds of ways to add comment in SAS:

*Any comment text here;
%*Any comment text here;
/*Any comment text here*/

This afternoon, I am kind of excited of finding the fourth way to add comment by coincidence. It is:

comment Any comment text here;

As you can see, the first word comment is a keyword here to trigger the following text becoming comment text. I have tried several programs:

/*comment of macro in open code*/
%put This is %sysfunc(date(),e8601da.);
comment %put This is %sysfunc(date(),e8601da.);

/*comment of macro*/
comment %cmprs(test);

/*comment after normal statement*/
data _null_; comment Hi there.;
run;

They all behaves like a normal comment way. Only one point, there mustn't exist a semicolon in the comment text.

I think there is enough exploration in SAS. I search in the help document and find nothing. My friend tells me this may be a pre-experience features, How do you know about it? Please share your idea.

1 Answers

COMMENT is a statement like any other submitted statement. In essence it is the same as * because the comment statement ends at the first semi-colon (;). The documentation does not specifically state * is an alias for COMMENT, but lists * ... ; and /* ... */.

Another way to comment multiple statements that also contain comment blocks is to nest the code inside a macro definition.

Example:

proc print data=sashelp.class;
run;

%macro MY_COMMENT;

* This part contains more statements;
proc print sashelp.cars;
run;
/* And there are comments in both styles of commenting */
%* But inside an uncalled macro everything acts like a giant comment block;

%mend MY_COMMENT;

* return to normal processing;

For very large blocks of commented code, during development of code, I will often wrap the commented part with NOSOURCE and SOURCE to prevent log clogging.

...

options NOSOURCE;
/*
Big chunk commented out during development to temporarily prevent
rerunning ETL process steps or regenerating already OK reporting code
*/
options SOURCE;

* work on new additional part of process flow here;
...

Other commenting tricks

Way 1 - /**/ pairs

If code is consistently commented with only *; style comments, then code blocks can be easily commented and uncommented using an introductory /**/ or /** / and a closing /**/ .

Uncommented - the intro is a plain comment

/**/  * some code here; /**/

Commented - the extra space in the intro causes the comment to be closed by the final */

/** / * some code here; /**/

Way 2 - /* *; */; toggle

Requires a *; comment as the first line of the block, and no /* */ comments within.

Toggle off, block code is commented out

/*
*intro;
... block ...
*/;

versus

Toggle on, block code is not commented out

*/*
*intro;
... block ...
*/;

Enhanced editor

  • Comment
    • Select a block of lines and press Ctrl-/.
      All the lines will become individual /*original line*/ style comment blocks.
  • Uncomment
    • Select a block of lines and press Ctrl-Shift-/.
      The leading /* and trailing */ of each line will be removed.

Macro variable

Use a flag variable with value or * as a statement introductory to enable or disable statements.

%if %sysget(USERNAME)=Richard %then %do;
  %let flag=*;
%end;
%else %do;
  %let flag=;
%end;

&flag. PROC PRINT ...;
&flag. ...;
&flag. ...;
&flag. run;
Related