character data. Data errors do not cause a program to stop. Instead, they generate notes
in the SAS log. These are some of the types of data errors:
defining a variable as numeric when the data value is actually character
generating missing values as a result of performing an operation on missing values
reading a variable with an INPUT statement when the variable is not in the correct
position in a file
using the Sum statement with character variables
Semantic Errors
Semantic errors are another type of an execution-time error. They occur when the form
of a SAS statement is correct, but some elements are not valid in a particular usage.
These are some of the types of semantic errors:
specifying the wrong number of arguments for a function
using a numeric variable name where only character variables are valid
using invalid references to an array
using a libref that has not yet been assigned
Diagnosing Errors
Examples in This Section
Many of the programs in this section use university test scores to illustrate errors in the
SAS log. Other programs in this section use other data.
Diagnosing Syntax Errors
When SAS Detects a Syntax Error
The SAS Supervisor detects syntax errors as it compiles each step, and then SAS does
the following:
writes the word ERROR to the log
identifies the error's location
writes an explanation of the error
Example: Missing Semicolon and Misspelled Keyword
In the following program, the CHART procedure is used to analyze data. Note that a
semicolon in the DATA statement is omitted, and the keyword INFILE is misspelled.
libname out 'your-data-library';
data out.error1
infill 'your-input-file';
input test $ gender $ year TestScore;
402 Chapter 25 Diagnosing and Avoiding Errors
run;
proc chart data=out.error1;
hbar test / sumvar=TestScore type=mean group=gender discrete;
run;
The following output shows the result of the two syntax errors:
Log 25.1 Diagnosing Syntax Errors: Missing Semicolon and Misspelled Keyword
11 libname out 'your-data-library';
NOTE: Libref OUT was successfully assigned as follows:
Engine: V9
Physical Name: your-data-library
12
13 data out.error1
14 infill 'your-input-file';
15 input test $ gender $ year TestScore;
16 run;
ERROR: No DATALINES or INFILE statement.
ERROR: Extension for physical file name "your-input-file" does not
correspond to a valid member type.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set OUT.ERROR1 may be incomplete. When this step was stopped
there were 0
observations and 4 variables.
WARNING: Data set OUT.ERROR1 was not replaced because this step was stopped.
WARNING: The data set WORK.INFILL may be incomplete. When this step was stopped
there were 0
observations and 4 variables.
WARNING: Data set WORK.INFILL was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
17
18 proc chart data=out.error1;
19 hbar test / sumvar=TestScore type=mean group=gender discrete;
20 run;
NOTE: No observations in data set OUT.ERROR1.
NOTE: PROCEDURE CHART used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
As the log indicates, SAS recognizes the keyword DATA and attempts to process the
DATA step. Because the DATA statement must end with a semicolon, SAS assumes that
INFILL is a data set name, and that two data sets are being created: OUT.ERROR1 and
WORK.INFILL. Because SAS considers INFILL the name of a data set, it does not
recognize it as part of another statement, and therefore does not detect the spelling error.
Because the string in quotation marks is invalid in a DATA statement, SAS stops
processing here and created no observations for either data set.
SAS attempts to execute the program logically based on the statements that it contains,
according to the steps outlined earlier in this section. The second syntax error, the
misspelled keyword, is never recognized because SAS considers the DATA statement to
be in effect until a semicolon ends the statement. The point to remember is that when
multiple errors are made in the same program, not all of them might be detected the first
time the program is executed. Errors might also be flagged differently in a group than if
Diagnosing Errors 403

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.