3 Editing and Debugging SAS Programs
1. Editing SAS Programs
To open a program, you can use
o file shortcuts
o My Favorite Folders
o the Open window
o the INCLUDE command:
INCLUDE 'file specification'
To save a SAS program, you can use the FILE command:
FILE 'file specification'
A consistent layout improves readability and understanding of the program’s purpose:
o being DATA and PROC steps in column one
o indent statements within a step
o begin RUN statements in column one
o include a RUN statement after every DATA step or PROC step
o insert comments
* This program prints data;
or
/* This program prints data */
SAS ignores all text between comment symbols when processing a SAS program.
Avoid placing the comment symbols in columns 1 and 2 because it is a command to
end the SAS job or session.
Example 1
Write a SAS command so that you can open D:\Programs\Sas\[Link] in the
Windows operating environment.
1
Example 2
Rewrite the following SAS program with improved readability.
data talent2; set [Link];
where day>20; proc print data=talent2;
run;
2. Debugging SAS Programs
Two common SAS errors are
o Syntax errors – statements do not conform to the rules of the SAS language
o Data errors – data values are not appropriate for the SAS statements
When a syntax error is detected, the Log window
o displays the word ERROR
o identifies the possible location of the error
o gives an explanation of the error
Common syntax errors are
o missing a RUN statement – “PROC (or DATA) step running” at top of active
window
o missing semicolon – log message indicating an error in a statement that seems
to be valid
o unbalanced quotation marks – log message indicating that a quoted string
has become too long or that a statement is ambiguous
o invalid options – log message indicating that an option is invalid or not
recognized
Procedure of correcting errors
o Cancel the submitted statements
o Correct the program
o Clear messages from the Log window
o Resubmit the program
o Check the Log window
To view the last submitted statement, you can
o use RECALL command, or
2
o Run -> Recall Last Submit
Example 3
Suppose that you submit the following program
proc prin data=[Link];
var id name fee;
run;
The following message appears in the Log window:
12 proc prin data=[Link];
ERROR: Procedure PRIN not found.
13 var id name fee;
14 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRIN used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
What does the message imply?
Example 4
What is wrong of the following program?
LIBNAME sas2014 'E:\sas2013
PROC PRINT DATA=[Link] (firstobs=1 obs=5);
PROC FREQ DATA=[Link];
QUIT;
3
3. Answers of Examples
1. include 'D:\Programs\Sas\[Link]'
2.
data talent2;
set [Link];
where day>20;
run;
proc print data=talent2;
run;
3. The message suggests that PRIN is a typo.
4. The first line misses ';