Syntax errors occur when program statements do not
conform to the rules of the SAS language. Here are some examples of
syntax errors:
-
-
unmatched quotation marks
-
-
-
When SAS encounters
a syntax error, it first attempts to correct the error by attempting
to interpret what you mean. Then SAS continues processing your program
based on its assumptions. If SAS cannot correct the error, it prints
an error message to the log. If you do not want SAS to correct syntax
errors, you can set the NOAUTOCORRECT system option. For more information,
see the AUTOCORRECT system option in the
SAS System Options: Reference.
In the following example,
the DATA statement is misspelled, and SAS prints a warning message
to the log. Because SAS could interpret the misspelled word, the program
runs and produces output.
date temp;
x=1;
run;
proc print data=temp;
run;
SAS Log: Syntax Error (Misspelled Key Word)
39 date temp;
----
14
WARNING 14-169: Assuming the symbol DATA was misspelled as date.
40 x=1;
41 run;
NOTE: The data set WORK.TEMP has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
42
43 proc print data=temp;
44 run;
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
45 proc printto; run;
Some errors are explained
fully by the message that SAS prints in the log. Other error messages
are not as easy to interpret because SAS is not always able to detect
exactly where the error occurred. For example, when you fail to end
a SAS statement with a semicolon, SAS does not always detect the
error at the point where it occurs. This is because SAS statements
are free-format (they can begin and end anywhere). In the following
example, the semicolon at the end of the DATA statement is missing.
SAS prints the word ERROR in the log, identifies the possible location
of the error, prints an explanation of the error, and stops processing
the DATA step.
data temp
x=1;
run;
proc print data=temp;
run;
SAS Log: Syntax Error (Missing Semicolon)
67 data temp
68 x=1;
-
22
76
ERROR 22-322: Syntax error, expecting one of the following: a name,
a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 76-322: Syntax error, statement will be ignored.
69 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
70
71 proc print data=temp;
72 run;
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
73 proc printto; run;
Whether subsequent steps
are executed depends on which method of running SAS you use, as well
as on your operating environment.
Note: You can add these lines to your code to fix unmatched
comment tags, unmatched quotation marks, and missing semicolons:
/* '; * "; */;
quit;
run;