1.6 - Guidelines for Formatting and Commenting SAS Programs

Regardless of the programming language used, there is a basic set of good programming practices to which any good programmer will adhere. Two good programming practices concern the formatting and commenting of your programs. Therefore, let's close this lesson by reviewing some guidelines for formatting and commenting your SAS programs. Throughout this course (and beyond!), you should plan on adhering to the following guidelines:

This SAS program blah, blah, blah, ..........

*Convert Fahrenheit to celsius;

As mentioned earlier, comment statements allow you to document your program without affecting processing. A delimited comment, which begins with a forward-slash-asterisk (/*) and ends with an asterisk-forward-slash (*/), is useful for creating large blocks of comments. All text within the delimiters are ignored. An alternative type of comment begins with an asterisk (*) and ends with a semicolon (;). Examples:

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

Filename: /home/lsimon/stat597c/sas/temp.sas
Written by: laura J. Simon
Date: January 9, 1996

This program calculates the average number of days that the tempreture falls below freezing in State College, PA

Input: C:\data\temps.dat
Output: average number of days below freezing by month stored in C:\data\temps.ssd

Every SAS program should start with a main block of comments, emphasized by asterisks. The block of comments should include the filename, by whom the program is written, the date on which the program was written, and text that clearly describes the main purpose, input and output of the program. Example:

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

temp_f = 1.8*temp_c+32; *Convert celsius to fahrenheit;

Comments that pertain to a single line of code are useful, e.g. for describing what an expression is calculating, describing a new variable and how it is calculated, why the dataset is subsetted on a particular set of values, and so on. Example:

At least one line should separate any PROC or DATA steps within your SAS program.

PROC PRINT data=stat480.temps;

DATA temps;
    set stat480.temps;
    if month in ('April','May','June');

To help offset blocks of code, it is useful to capitalize PROC PROCNAME, DATA, and RUN. Examples:

PROC PRINT data=stat480.temps;
    title 'Tempretures in April, May, June';
    var month loc time_hr time_min am_pm temp_c temp_f;

Any code contained within a DATA step or PROC step should be indented at least two spaces to improve legibility. Keywords within the DATA steps or PROC steps, such as title, variable, table, should be easily identified. Example:

Up and coming!

In this lesson, we just basically got you up and running on the SAS System. In the next lesson, we'll spend time learning how to read your data into the SAS data sets that the SAS System understands.