ABORT Statement

Stops executing the current DATA step, SAS job, or SAS session.

Valid in: DATA step
Category: Action
Type: Executable
Restriction: This statement is not supported in a DATA step that runs in CAS.
UNIX specifics: Values of n
Windows specifics: Action of the ABEND and RETURN options; maximum value of condition-code
z/OS specifics: Action of ABEND and RETURN, maximum value of n
See: ABORT Statement in SAS Companion for Windows, SAS Companion for z/OS, and SAS Companion for UNIX Environments

Syntax

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

UNIX:

ABORT <ABEND | RETURN> <n>;

Windows:

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

z/OS:

ABORT <ABEND | RETURN> <n> ;

Without Arguments

If you specify no argument, the ABORT statement triggers the following actions under these 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 checking the syntax 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 SAS log that an ABORT statement terminated the DATA step.
  • continues processing any DATA and 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. Actions 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
    • stops processing immediately and returns you to your operating environment.
Windows Specifics: Further action is based on how your operating environment and site treat jobs that end abnormally.
z/OS Specifics: Causes normal z/OS abend processing to occur after the ABORT statement is issued.

CANCEL <FILE>

causes the execution of the submitted statements to be canceled. Actions depend on the method of operation.

  • batch mode and noninteractive mode
    • terminates the entire SAS program.
    • writes an error message to the SAS log.
  • windowing environment and interactive line mode
    • clears only the current submitted program.
    • does not affect other subsequent submitted programs.
    • writes an error to the SAS log.
  • workspace server and stored process server
    • clears only the currently submitted program.
    • does not affect other subsequent submit calls.
    • writes an error message 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 are executed after the autoexec file 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 that states 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 that indicates an error.
  • windowing environment and interactive line mode
    • stops processing immediately and returns you to your operating environment.
Windows Specifics: A condition code that indicates an error is returned if a job ends abnormally.

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 exit code.
UNIX Specifics: The n option enables you to specify the value of the exit status code that SAS returns to the shell when it stops executing. The value of n can range from 0 to 255. Normally, a return code of 0 is used to indicate that the program ran with no errors. Return codes greater than 0 are used to indicate progressively more serious error conditions. Return codes of 0–6 and those codes that are greater than 977 are reserved for use by SAS.
Windows Specifics: Enables you to specify a condition code that SAS returns to its calling program. The value of n must be an integer. Return codes 0–6 and those values that are greater than 997 are used by SAS.

NOLIST

suppresses the output of all variables to the SAS log.

Requirement NOLIST must be the last option in the ABORT statement.

Details

General Information

The ABORT statement causes SAS to stop processing the current DATA step. What happens next depends on the following information:

  • 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 in a SELECT statement that is designed to stop processing when an error occurs.

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.

Note: The return code that is generated by the ABORT statement is ignored by SAS if the system option ERRORABEND is in effect.
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.

Information That Is Specific to UNIX

The n option enables you to specify the value of the exit status code that SAS returns to the shell when it stops executing. The value of n can range from 0 to 255. Normally, a return code of 0 is used to indicate that the program ran with no errors. Return codes greater than 0 are used to indicate progressively more serious error conditions. Return codes of 0–6 and those codes that are greater than 977 are reserved for use by SAS.

Information That Is Specific to Windows

The ABEND and RETURN options both terminate the SAS process, job, or session.

Information That Is Specific to z/OS

You can use the ABORT statement to control the conditional execution of z/OS job steps. For example, depending on the result of the z/OS job step that executes your SAS program, you might need to either bypass or execute later steps. To enable this control, establish a variable in your SAS DATA step program that is set to a particular value whenever an error occurs. In this example, a variable named Errcode is set to 16 if an error occurs in the DATA step. You can choose any variable name and value that are required by your program. Then, use the ABORT statement, coded in the THEN clause of an IF statement, to cause the z/OS job step to ABEND if ERRCODE=16.

if errcode=16 then abort return;

When the z/OS job step that is used to execute your SAS job ends (either normally or abnormally), the next z/OS job step is processed. You could then use this EXEC statement to conditionally execute that job step if an ABEND occurs. If ERRCODE is not set to 16, the ABORT statement is disabled, and because an ABEND did not occur the job step is bypassed.

//stepname EXEC
PGM=your-program,COND=ONLY

If a SAS session abends when it is processing an ABORT statement, and SAS allocated data sets during FILENAME or LIBNAME processing, then SAS uses the normal termination disposition to deallocate the data sets. For more information, see the description of the DISP option for FILENAME Statement: z/OS in SAS Companion for z/OS or LIBNAME Statement: z/OS in SAS Companion for z/OS.

Comparisons

  • In batch or noninteractive mode, the ABORT and STOP statements have different effects. The ABORT statement stops processing and sets the value of the automatic variable _ERROR_ to 1. The STOP statement stops processing the current DATA step and continues processing with the next step.
  • When you use the SAS windowing environment or interactive line mode, the ABORT and STOP statements stop processing. The ABORT statement sets the value of the automatic variable _ERROR_ to 1. The STOP statement does not set a value.

Example: Stopping Execution of SAS

This example uses the ABORT statement as part of an IF-THEN statement to stop processing when SAS encounters a data value that would otherwise cause a division-by-zero condition.


data test;
   mass=100;
   volume=0;
   if volume=0 then abort 255;
   density=mass/volume;
run;

When the ABORT statement executes, SAS returns the condition code 255 to the operating environment.

See Also

Last updated: June 17, 2025