ABORT Statement

Stops executing the current DATA step, SAS job, or SAS session.
Valid in: DATA step
Category: Action
Type: Executable
See: ABORT Statement in the SAS Companion for Windows, SAS Companion for z/OS, and SAS Companion for UNIX Environments

Syntax

ABORT <ABEND | CANCEL <FILE> | RETURN > <n> <NOLIST>;

Without Arguments

If you specify no argument, the ABORT statement produces these results under the following methods of operation:
batch mode and noninteractive mode
  • stops processing the current DATA step and writes an error message to the SAS log. Data sets can contain an incomplete number of observations or no observations, depending on when SAS encountered the ABORT statement.
  • sets the OBS= system option to 0.
  • continues limited processing of the remainder of the SAS job, including executing macro statements, executing system options statements, and syntax checking of program statements.
  • creates output data sets for subsequent DATA and PROC steps with no observations.
windowing environment
  • stops processing the current DATA step
  • creates a data set that contains the observations that are processed before the ABORT statement is encountered
  • prints a message to the log that an ABORT statement terminated the DATA step
  • continues processing any DATA or PROC steps that follow the ABORT statement
interactive line mode
stops processing the current DATA step. Any further DATA steps or procedures execute normally.

Arguments

ABEND
causes abnormal termination of the current SAS job or session. Results depend on the method of operation:
  • batch mode and noninteractive mode.
    • stops processing immediately.
    • sends an error message to the SAS log that states that execution was terminated by the ABEND option of the ABORT statement.
    • does not execute any subsequent statements or check syntax.
    • returns control to the operating environment; further action is based on how your operating environment and your site treat jobs that end abnormally.
  • windowing environment and interactive line mode.
    • causes your windowing environment and interactive line mode to stop processing immediately and return you to your operating environment.
CANCEL <FILE>
causes the execution of the submitted statements to be canceled. Results depend on the method of operation:
  • batch mode and noninteractive mode.
    • the entire SAS program and SAS system are terminated.
    • an error message is written to the SAS log.
  • windowing environment and interactive line mode.
    • clears only the current submitted program.
    • other subsequent submitted programs are not affected.
    • an error message is written to the SAS log.
  • workspace server and stored process server.
    • clears only the currently submitted program.
    • other subsequent submit calls are not affected.
    • an error message is written to the SAS log.
  • SAS IntrNet application server.
    • creates a separate execution for each request and submits the request code. A CANCEL argument in the request code clears the current submitted code but does not terminate the execution or the SAS session.
FILE
when coded as an option to the CANCEL argument in an autoexec file or in a %INCLUDE file, causes only the contents of the autoexec file or %INCLUDE file to be cleared by the ABORT statement. Other submitted source statements will be executed after the autoexec or %INCLUDE file.
Restriction:The CANCEL argument cannot be submitted using SAS/SHARE,SAS/CONNECT, or SAS/AF.
Note:When the ABORT CANCEL FILE option is executed within a %INCLUDE file, all open macros are closed and execution resumes at the next source line of code.
RETURN
causes the immediate normal termination of the current SAS job or session. Results depend on the method of operation:
  • batch mode and noninteractive mode
    • stops processing immediately
    • sends an error message to the SAS log stating that execution was terminated by the RETURN option in the ABORT statement
    • does not execute any subsequent statements or check syntax
    • returns control to your operating environment with a condition code indicating an error
  • windowing environment
    • causes your windowing environment and interactive line mode to stop processing immediately and return you to your operating environment.
n
is an integer value that enables you to specify a condition code:
  • when used with the CANCEL argument, the value is placed in the SYSINFO automatic macro variable
  • when not used with the CANCEL argument, the error code that is returned by SAS is ERROR. The value of ERROR depends on the operating system. The condition code n is returned to the operating system as the final SAS system exit code.
NOLIST
suppresses the output of all variables to the SAS log.
Requirement:NOLIST must be the last option in the ABORT statement.

Details

The ABORT statement causes SAS to stop processing the current DATA step. What happens next depends on
  • the method that you use to submit your SAS statements
  • the arguments that you use with ABORT
  • your operating environment.
The ABORT statement usually appears in a clause of an IF-THEN statement or a SELECT statement that is designed to stop processing when an error condition occurs.
Note: The return code generated by the ABORT statement is ignored by SAS if the system option ERRORABEND is in effect.
Note: When you execute an ABORT statement in a DATA step, SAS does not use data sets that were created in the step to replace existing data sets with the same name.
Operating Environment Information: The only difference between the ABEND and RETURN options is that with ABEND further action is based on how your operating environment and site treat jobs that end abnormally. RETURN simply returns a condition code that indicates an error.

Comparisons

  • When you use the SAS windowing environment or interactive line mode, the ABORT statement and the STOP statement both stop processing. The ABORT statement sets the value of the automatic variable _ERROR_ to 1, and the STOP statement does not.
  • In batch or noninteractive mode, the ABORT and STOP statements also have different effects. Both stop processing, but only ABORT sets the value of the automatic variable _ERROR_ to 1. Use the STOP statement, therefore, when you want to stop only the current DATA step and continue processing with the next step.

Example: Stopping Execution of SAS

This example uses the ABORT statement as part of an IF-THEN statement to stop execution of SAS when it encounters a data value that would otherwise cause a division-by-zero condition.
if volume=0 then abort 255;
   density=mass/volume;
The n value causes SAS to return the condition code 255 to the operating environment when the ABORT statement executes.

See Also

Statements: