When Comments Go Bad
Here's a short discussion which arose from a Macro class room conversation on commenting SAS code and particularly when commenting Macro code.
For certain, the automated code documentation afforded by the tools such as of Enterprise Guide and Data Integration Studio are a huge leap forward – but for user written code it too often forgotten that there are three types of comment in SAS language… and with good reason:
Firstly the block comment /* comments here */ is the style associated with many programming languages such as C# or PL/1. Between the open and close comments the text is hidden from the SAS processor – hence can contain any text, even unbalanced quotes.
The second comment is known as a line comment and extends from an * to the next;. SAS treats these comments as tokens in code. This has a real impact when you comment in macro. Consider:
%if &bool=True %then %do; %end; * Line Comment Here; %else %if &bool=False %then %do; %end;
On compiling this macro an error is seen implying the %else statement has no corresponding %if. To solve this problem we can use the third comments style (macro comments) which hides these tokens from the macro processor in our SAS session. Note the prefixed percent sign:
%* Line Comment Here;
Your thoughts and of course comments are welcome!