SAS-Efficient Coding Techniques-4:Commenting, UnCommenting & Collapsing of codes/Comments



SAS-Commenting, UnCommenting & Collapsing of codes/Comments

Please note that the following Is applicable for ENHANCED EDITOR.
Commenting: You might be aware of the old fashioned way of commenting, which is putting an astrix in ‘*’ followed by semicolon at the end of the line ‘;’. For example
DATA XYZ;
SET ABC;
FORMAT STATUS $20.;
IF FLAG = 0 THEN STATUS = "BRAND NEW";
ELSE IF FLAG = 1 THEN STATUS = "NEVER BUYS";
*Comment;
*ELSE IF FLAG = 2 THEN STATUS = "RARELY BUYS";
ELSE IF FLAG = 5 THEN STATUS = "SPENDTHRIFT";
RUN;
You can also comment by placing the comment or code in between “/*” and “*/”. This can be done using the following shortcut “CTRL + / “. Even if you have a word selected or if you have the cursor in that line the entire line is commented by pressing the keys.For example
/*To this step I want to add a Comment */
DATA XYZ;
SET ABC;
FORMAT STATUS $20.;
IF FLAG = 0 THEN STATUS = "BRAND NEW";
ELSE IF FLAG = 1 THEN STATUS = "NEVER BUYS";
*Comment;
*ELSE IF FLAG = 2 THEN STATUS = "RARELY BUYS";
ELSE IF FLAG = 3 THEN STATUS = "RANDOMLY BUYS";
/*Comment*/
/*ELSE IF FLAG = 4 THEN STATUS = "REGULARLY BUYS";*/
ELSE IF FLAG = 5 THEN STATUS = "SPENDTHRIFT";
RUN;
UnCommenting: Uncommenting can be done by simply using the following shortcut “CTRL + SHIFT + /
Collapsing the code:
When a code is written in enhanced editor we see a “-” sign next to the starting line of the code. Clicking on this replaces the entire code with just the first line of the code and we have a “+” sign next to it.


. So the short cut for doing this is “Alt + Ctrl +( Number pad) - “ and to expand it “Alt + Ctrl + (Number pad ) +“.
Collapsing the Comments:
Sometimes it is annoying to see the commented part of the code in the editor again and again. Say for example you are doing a final check you need to scroll through the entire commented part, this is particularly painful when dealing you are dealing with large codes.
Any way to get around this we write something called the ‘Dead Code’ Macro. All you do is put your code in this macro and then you can collapse it so you have see the unnecessary part again and again.


  1. gravatar

    # by Irina - August 18, 2009 at 5:03 PM

    Hi the short cut Alt + Ctrl +( Number pad) - doesn't seem to work for me ...

  2. gravatar

    # by Analyst - August 19, 2009 at 12:55 AM

    This comment has been removed by the author.

  3. gravatar

    # by Analyst - August 19, 2009 at 12:58 AM

    Hey Irina, the short cut works only with the numpad or in other words, it does not work with the laptop keyboard. I hope i understood your question right.

Blog Widget by LinkWithin

Search this blog..

Loading