SAS Institute. The Power to Know

SAS(R) 9.2 Language Reference: Concepts

Previous Page | Next Page

Error Processing and Debugging

Error Processing in SAS


Syntax Check Mode


Overview of Syntax Check Mode

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. You do this by setting the SYNTAXCHECK system option in batch or non-interactive mode, or by setting the DMSSYNCHK system option in the windowing environment.

SAS can enter syntax check mode only if your program creates a data set. If you use the DATA _NULL_ statement, then SAS cannot enter syntax check mode because no data set is created. In this case, using the SYNTAXCHECK or DMSSYNCHK system option has no effect.

In 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.   [cautionend]

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.


Enabling Syntax Check Mode

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. You can use these system options only if your program creates a data set. If you use the DATA _NULL_ statement, then these options are ignored.

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 these system options, see DMSSYNCHK and SYNTAXCHECK system option, in SAS Language Reference: Dictionary.


Processing Multiple Errors

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 types of errors. Thus, in some cases SAS can detect multiple errors in a single statement and might 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;

SAS Log: Multiple Program Errors

      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.


Checkpoint Mode and Restart Mode


Overview of Checkpoint Mode and Restart Mode

Used together, checkpoint mode and restart mode enable batch programs that terminate before completing to be resubmitted, resuming execution with the DATA or PROC step that was executing when the failure occurred. DATA and PROC steps that already completed will not be re-executed.

When checkpoint mode is enabled, SAS records information about DATA and PROC steps in a checkpoint library. When a batch program terminates prematurely, you can resubmit the program in restart mode to complete execution. In restart mode, global statements and macros are re-executed and SAS reads the data in the checkpoint library to determine which steps completed. Program execution resumes with the step that was executing when the failure occurred.

The checkpoint-restart data contains only information about the DATA and PROC steps that completed and the step that did not complete. It does not contain information about macro variables, macro definitions, SAS data sets, or any other information that might have been processed in the step that did not complete.

If a step must be reexecuted, you can add the global statement CHECKPOINT EXECUTE_ALWAYS immediately before the step. This statement tells SAS to always execute the following step without considering the checkpoint-restart data.

Checkpoint mode is not valid for batch programs that contain the DM statement to submit commands to SAS. If checkpoint mode is enabled and SAS encounters a DM statement, checkpoint mode is disabled and the checkpoint catalog entry is deleted.

You enable checkpoint mode and restart mode by using system options when you start the batch program in SAS. You can also use one or more CHECKPOINT statements in the batch program:

  • STEPCHKPT system option enables checkpoint mode, which indicates to SAS to record checkpoint-restart data

  • STEPCHKPTLIB system option identifies a user-specified checkpoint-restart library

  • STEPRESTART system option enables restart mode, ensuring that execution resumes with the DATA or PROC step indicated by the checkpoint-restart library.

  • CHECKPOINT EXECUTE_ALWAYS is a global statement that can be placed before a DATA or PROC step to indicate that the step that immediately follows must be executed, even if the checkpoint-restart data shows that the step already completed. It is applicable only to the step that follows the statement.

In order for checkpoint mode and restart mode to work successfully, the number and order of the DATA and PROC steps in the batch program must not change between SAS invocations. By specifying the ERRORABEND and ERRORCHECK system options when SAS starts, SAS will terminate for most error conditions in order to maintain valid checkpoint-restart data.

The checkpoint-restart library can be a user-specified library or, if no library is specified, the checkpoint-restart data is saved to the WORK library. If the WORK library is used, the NOWORKTERM and NOWORKINIT system options must be specified when SAS starts to ensure that the checkpoint-restart data is not lost. SAS writes the name of the WORK library to the SAS log.

For information about the system options and the statement, see STEPCHKPT System Option, STEPCHKPTLIB System Option, STEPRESTART System Option, and CHECKPOINT EXECUTE_ALWAYS Statement in SAS Language Reference: Dictionary


Setting Up and Executing Checkpoint Mode and Restart Mode

To set up checkpoint mode and restart mode, make the following modification to your batch program:

  • Add the CHECKPOINT EXECUTE_ALWAYS statement before any DATA and PROC steps that you want to execute each time the batch program is submitted.

  • If your checkpoint-restart library is a user-defined library, you must add the LIBNAME statement that defines the checkpoint-restart libref as the first statement in the batch program. If you use the WORK library as your checkpoint library, no LIBNAME statement is necessary.

Once the batch program has been modified, you start the program using the appropriate system options:
  • For checkpoint-restart data that is saved in the WORK library, start a batch SAS session that specifies these system options:

    • SYSIN, if required in your operating environment, names the batch program

    • STEPCHKPT enables checkpoint mode

    • NOWORKTERM saves the WORK library when SAS ends

    • NOWORKINIT does not initialize the WORK library when SAS starts

    • ERRORCHECK STRICT puts SAS in syntax-check mode when an error occurs in the LIBNAME, FILENAME, %INCLUDE, and LOCK statements

    • ERRORABEND specifies whether SAS terminates for most errors

    In the Windows operating environment, the following SAS command starts a batch program in checkpoint mode using the WORK library as the checkpoint-restart library:

    sas -sysin 'c:\mysas\myprogram.sas' -stepchkpt -noworkterm -noworkinit
        -errorcheck strict  -errorabend
  • For checkpoint-restart data that is saved in a user-specified library, start a batch SAS session that includes these system options:

    • SYSIN, if required in your operating environment, names the batch program

    • STEPCHKPT enables checkpoint mode

    • STEPCHKPTLIB specifies the libref of the library where SAS saves the checkpoint-restart data

    • ERRORCHECK STRICT puts SAS in syntax-check mode when an error occurs in the LIBNAME, FILENAME, %INCLUDE, and LOCK statements

    • ERRORABEND specifies whether SAS terminates for most errors

    In the Windows operating environment, the following SAS command starts a batch program in checkpoint mode using a user-specified checkpoint-restart library:

    sas -sysin 'c:\mysas\myprogram.sas' -stepchkpt -stepchkptlib mylibref 
        -errorcheck strict -errorabbend
    In this case, the first statement in myprogram.sas is the LIBNAME statement that defines the mylibref libref.

Restarting Batch Programs

To resubmit a batch SAS session using the checkpoint-restart data that is saved in the WORK library, include these system options when SAS starts:

  • SYSIN, if required in your operating environment, names the batch program

  • STEPCHKPT continues checkpoint mode

  • STEPRESTART enables restart mode, indicating to SAS to use the checkpoint-restart data

  • NOWORKINIT starts SAS using the WORK library from the previous SAS session

  • NOWORKTERM saves the WORK library when SAS ends

  • ERRORCHECK STRICT puts SAS in syntax-check mode when an error occurs in the LIBNAME, FILENAME, %INCLUDE, and LOCK statements

  • ERRORABEND specifies whether SAS terminates for most errors

In the Windows operating environment, the following SAS command resubmits a batch program whose checkpoint-restart data was saved to the WORK library:
sas -sysin 'c:\mysas\mysasprogram.sas' -stepchkpt -steprestart -noworkinit 
   -noworkterm  -errorcheck strict -errorabend

By specifying the STEPCHKPT and NOWORKTERM system options, checkpoint mode continues to be enabled once the batch program restarts.

To resubmit a batch SAS session using the checkpoint-restart data that is saved in a user-specified library, include these system options when SAS starts:

  • SYSIN, if required in you operating environment, names the batch program

  • STEPCHKPT continues checkpoint mode

  • STEPRESTART enables restart mode, indicating to SAS to use the checkpoint-restart data

  • STEPCHKPTLIB specifies the libref of the checkpoint-restart library

  • ERRORCHECK STRICT puts SAS in syntax-check mode when an error occurs in the LIBNAME, FILENAME, %INCLUDE, and LOCK statements

  • ERRORABEND specifies whether SAS terminates for most errors

In the Windows operating environment, the following SAS command resubmits a batch program whose checkpoint-restart data was saved to a user-specified library:
sas -sysin 'c:\mysas\mysasprogram.sas' -stepchkpt -steprestart -stepchklib 
   mylibref -errorcheck strict -errorabend


Using System Options to Control Error Handling

You can use the following system options to control error handling (resolve errors) in your program:

BYERR

specifies whether SAS produces errors when the SORT procedure attempts to process a _NULL_ data set.

DKRICOND=

specifies the level of error detection to report when a variable is missing from an input data set during the processing of a DROP=, KEEP=, and RENAME= data set option.

DKROCOND=

specifies the level of error detection to report when a variable is missing from an output data set during the processing of a DROP=, KEEP=, and RENAME= data set option.

DSNFERR

when a SAS data set cannot be found, specifies whether SAS issues an error message.

ERRORABEND

specifies whether SAS responds to errors by terminating.

ERRORCHECK=

specifies whether SAS enters syntax-check mode when errors are found in the LIBNAME, FILENAME, %INCLUDE, and LOCK statements.

ERRORS=

specifies the maximum number of observations for which SAS issues complete error messages.

FMTERR

when a variable format cannot be found, specifies whether SAS generates an error or continues processing.

INVALIDDATA=

specifies the value that SAS assigns to a variable when invalid numeric data is encountered.

MERROR

specifies whether SAS issues a warning message when a macro-like name does not match a macro keyword.

QUOTELENMAX

if a quoted string exceeds the maximum length allowed, specifies whether SAS writes a warning message to the SAS log.

SERROR

specifies whether SAS issues a warning message when a macro variable reference does not match a macro variable.

STEPCHKPT

specifies whether checkpoint-restart data is to be recorded for a batch program.

STEPCHKPTLIB

specifies the libref of the library where checkpoint-restart data is saved.

STEPRESTART

specifies whether to execute a batch program by using checkpoint-restart data.

VNFERR

specifies whether SAS issues an error or warning when a BY variable exists in one data set but not another data set when processing the SET, MERGE, UPDATE, or MODIFY statements.

For more information about SAS system options, see SAS Language Reference: Dictionary.


Using Return Codes

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.   [cautionend]


Other Error-Checking Options

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 ERRORS= 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 automatic macro variable to receive return codes

  • the SYSERR automatic macro variable to detect major system errors, such as out of memory or failure of the component system

  • 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.

Previous Page | Next Page | Top of Page