SAS Scripts - Better Exit Codes
October 23, 2020•232 words
Normally, if a SAS script generates any warnings the exit code is 1, which is generally interpreted as an error by the terminal. To avoid this, we can run SAS through a batch script which converts exit code 1 to 0 (meaning OK).
The batch script can be found here.
:: Name: sascli.cmd :: Purpose: Run SAS scripts with more generous exit codes. Normally, if a SAS :: script runs with warnings the exit code is 1 (interpreted as an :: error). This script converts exit code 1 to 0 (meaning OK). :: sas: 0 -> sascli: 0 :: sas: 1 -> sascli: 0 :: sas: i -> sascli: i, i != 0,1 :: sascli with no arguments -> sascli: 1 :: Author: Peter Alping :: Source: https://gitlab.com/snippets/1948149 :: Updated: 2020-10-23 :: :: Example use: :: sascli path/to/script.sas -nosplash -icon -log path/to/script.log @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION :: If no arguments exit with error code 1 IF "%~1" == "" ( EXIT /B 1 ) :: Run SAS with all command-line arguments and wait for it to finish START /WAIT "sas" sas %* :: Set exitcode to what is returned by SAS SET exitcode=%ERRORLEVEL% :: If only warnings (ERRORLEVEL==1) set exitcode to 0 IF %exitcode% == 1 ( SET exitcode=0 @ECHO ON ECHO WARNING: SAS exited with WARNINGS, check the logs @ECHO OFF ) :: Exit with exitcode EXIT /B %exitcode%