If you want processing to stop when a statement in a DATA step has a syntax error, you can enable SAS to enter syntax check mode. SAS internally sets the OBS= option to 0 and the REPLACE/NOREPLACE option to NOREPLACE. When these options are in effect, SAS acts as follows :
reads the remaining statements in the DATA step or PROC step
checks that statements are valid SAS statements
executes global statements
writes errors to the SAS log
creates the descriptor portion of any output data sets that are specified in program statements
does not write any observations to new data sets that SAS creates
does not execute most of the subsequent DATA steps or procedures in the program (exceptions include PROC DATASETS and PROC CONTENTS).
Note | Any data sets that are created after SAS has entered syntax check mode do not replace existing data sets with the same name . |
When syntax checking is enabled, if SAS encounters a syntax or semantic error in a DATA step, SAS underlines the point where it detects the error and identifies the error by number. SAS then enters syntax check mode and remains in this mode until the program finishes executing. When SAS enters syntax check mode, all DATA step statements and PROC step statements are validated .
You use the SYNTAXCHECK system option to enable syntax check mode when you run SAS in non-interactive or batch mode. You use the DMSSYNCHK system option to enable syntax check mode when you run SAS in the windowing environment. To disable syntax check mode, use the NOSYNTAXCHECK and NODMSSYNCHK system options.
In an OPTIONS statement, place the OPTIONS statement that enables SYNTAXCHECK or DMSSYNCHK before the step for which you want it to apply. If you place the OPTIONS statement inside a step, then SYNTAXCHECK or DMSSYNCHK will not take effect until the beginning of the next step.
For more information about the DMSSYNCHK system option and the SYNTAXCHECK system option in SAS Language Reference: Dictionary .
Depending on the type and severity of the error, the method you use to run SAS, and your operating environment, SAS either stops program processing or flags errors and continues processing. SAS continues to check individual statements in procedures after it finds certain kinds of errors. Thus, in some cases SAS can detect multiple errors in a single statement and may issue more error messages for a given situation, particularly if the statement containing the error creates an output SAS data set.
The following example illustrates a statement with two errors:
data temporary; Item1=4; run; proc print data=temporary; var Item1 Item2 Item3; run;
cpu time 0.00 seconds 1 data temporary; 2 Item1=4; 3 run; NOTE: The data set WORK.TEMPORARY has 1 observations and 1 variables. NOTE: DATA statement used: real time 0.10 seconds cpu time 0.01 seconds 4 5 proc print data=temporary; ERROR: Variable ITEM2 not found. ERROR: Variable ITEM3 not found. 6 var Item1 Item2 Item3; 7 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE PRINT used: real time 0.53 seconds cpu time 0.01 seconds
SAS displays two error messages, one for the variable Item2 and one for the variable Item3.
When you are running debugged production programs that are unlikely to encounter errors, you might want to force SAS to abend after a single error occurs. You can use the ERRORABEND system option to do this.
You can use the following system options to control error handling (resolve errors) in your program:
BYERR | controls whether SAS generates an error message and sets the error flag when a _NULL_ data set is used in the SORT procedure. |
DKRICOND= | controls the level of error detection for input data sets during the processing of DROP=, KEEP=, and RENAME= data set options. |
DKROCOND= | controls the level of error detection for output data sets during the processing of DROP=, KEEP=, and RENAME= data set options and the corresponding DATA step statements. |
DSNFERR | controls how SAS respondswhen a SAS data set is not found. |
ERRORABEND | specifies how SAS responds to errors. |
ERRORCHECK= | controls errorhandling in batch processing. |
ERRORS= | controls the maximum number of observations for which complete error messages are printed. |
FMTERR | determines whether SAS generates an error message when a format of a variable cannot be found. |
INVALIDDATA= | specifies the value that SAS assigns to a variable when invalid numeric data is encountered . |
MERROR | controls whether SAS issues a warning message when a macro-like name does not match a macro keyword. |
SERROR | controls whether SAS issues a warning message when a defined macro variable reference does not match a macro variable. |
VNFERR | controls how SAS responds when a _NULL_ data set is used. |
For more information about SAS system options, see SAS Language Reference: Dictionary .
In some operating environments, SAS passes a return code to the system, but the way in which return codes are accessed is specific to your operating environment.
Operating Environment Information: For more information about return codes, see the SAS documentation for your operating environment.
To help determine your programming errors, you can use the following methods :
the _IORC_ automatic variable that SAS creates (and the associated IORCMSG function) when you use the MODIFY statement or the KEY= data set option in the SET statement
the ERROR= system option to limit the number of identical errors that SAS writes to the log
the SYSRC and SYSMSG functions to return information when a data set or external-files access function encounters an error condition
the SYSRC and SYSERR macro variables
log control options:
MSGLEVEL= | controls the level of detail in messages that are written to the SAS log. |
PRINTMSGLIST | controls the printing of extended lists of messages to the SAS log. |
SOURCE | controls whether SAS writes source statements to the SAS log. |
SOURCE2 | controls whether SAS writes source statements included by %INCLUDE to the SAS log. |