Users of SAS® software ask frequently how to pass return codes from their SAS programs to subsequent steps in a batch job, or how to read the return codes from previous steps in order to control SAS execution. The following examples show how to manage return codes with SAS.
A return code can be set in a SAS program with the SAS SYSCC macro variable or with the ABORT RETURN statement. The SYSCC macro variable is a Read/Write automatic macro variable. If the SYSCC has been modified by a SAS program, at the program termination the host operating system translates the last value of the SYSCC to a meaningful host return code value. For z/OS, the following translation takes place:
SYSCC value | System return code |
0 | 0 |
1-4 | 4 |
>4 | 8 |
For example, if a SAS program completes and the last value of the SYSCC is 100, the MVS host environment translates the value and sets the job step return code to 8.
Using the SAS SYSCC Macro Variable
The following example shows how you might set the SYSCC to 4 in one DATA step, and then check the value in a subsequent DATA step in the same SAS program.
DATA test;
x=1;
*setting COND to 4 via SYSCC automatic macro variable;
IF x=1 THEN CALL SYMPUT('SYSCC','4');
run;
*display value of automatic macro variable;
%PUT &SYSCC;
DATA test2;
y=1;
RUN;
*display value of automatic macro variable SYSCC to;
*see if it has changed even after a successful Data step;
%PUT &SYSCC;
Using the ABORT RETURN Statement
You can use the SAS statement ABORT RETURN to set the return code that is returned to the host system. Although the SAS ABORT statement terminates the SAS session, the host can test for the RETURN value. For example, ABORT RETURN 100 terminates the SAS session and sets the operating system return code to 100.
In batch jobs, if you want to test the return code from a previous job step in order to conditionally execute a subsequent step, you should use the JCL COND= parm or the JCL IF/THEN/ELSE statement construct. Basic examples follow that use JCL to check the RC in a job step.
This example executes the step if the return code of the previous step was less than 8, and bypasses the step if it was equal to or greater than 8:
//SASSTEP EXEC SAS9,COND=(8,LE)
This example uses the JCL IF/THEN/ELSE statement to determine execution flow:
//STEP1 EXEC yourSASproc
//SYSIN DD *
DATA _NULL_;
ABORT RETURN 1111;
RUN;
//STEP2 IF (RC = 1111) THEN
//TRUE EXEC yourSASproc
//SYSIN DD *
DATA _NULL_;
PUT 'TRUE';
RUN;
// ELSE
//FALSE EXEC yourSASproc
//SYSIN DD *
DATA _NULL_;
PUT 'FALSE';
RUN;
//ENDTEST ENDIF
You should refer to the IBM JCL manuals for a complete description of the COND= parm or the JCL IF/THEN/ELSE statement.
Using a Temporary File Allocated by the Job
An optional method for controlling a job flow that uses results from a previous SAS step is to use a temporary file that is allocated by the job. The temporary file can be used by all job steps to write "return codes" or some manner of status indication that can be read by a later step in the job. This will allow a SAS step to determine the logic flow, based on results from a previous step from within the SAS program.
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.1 TS1M3 SP4 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.