About HPC Systems Software User Guides Education Partners

  / gears / hpc / education / tutorials / sas / formatting


Overview

Starting Out with SAS

Analyzing and Work with Data

Recommended Books

SAS Field Guide

SAS Facts

Formatting and Commenting SAS Programs

Formatting and Commenting SAS Programs


Comment statements allow you to document your program without affecting processing. There are two kinds of comments in SAS:

  1. All text between the delimiters /* and */ are ignored.
           /* This is a comment. */
    
  2. If a comment is short, it can be put between a * and ;.
           * This is another comment;
    

Although SAS allows for free-formatted code, a good SAS program will be well-documented and well-organized.

After the (optional) system OPTIONS statement, every SAS program should begin with a block of comments. This block of comments should include the name of the program file, the author, the date on which the program was written, and text that clearly describes the main purpose, input and output of the program. Example:

/*

 Filename: class.sas
 Written by: Dave Steven
 Date: January 14, 1997

 ...

*/

Every critical DATA step or PROC step alsoshould be preceded by a block of comments, emphasized by asterisks, that describes the primary purpose of the step. The block of comments also should include any critical information, such as variable names, input and output of the block of code.

Comments that pertain to a single line of code are useful, for example, to describe what an expression is calculating, to describe a new variable and how it is calculated, why a dataset is subsetted on a particular set of values, and so on. Here's an example of describing a new variable:

   temp_f = 1.8 * temp_c + 32;   * Convert Celsius to Fahrenheit;

At least one line, preferably two lines, should separate any DATA or PROC steps within your SAS programs.

Some people find it useful to capitalize DATA, PROC PROCNAME, and RUN. For example:

  DATA cool;
    set NewSASv8;
    ...
  RUN;

Indenting code within a DATA step or PROCedure at least 2 spaces has been known by many to improve readibility.


Please send questions or suggestions about this web page to beatnic@aset.psu.edu

ASET | ITS | Penn State