Syscc and syserrortext in sas

Viewed 744

I am trying to use the automatic macro variables in SAS for error handling, I found that &syscc will be 0 when an %include statement fails due to a nonexistent file. If I am relying on &syserrortext to capture this error message, I can cannot reset the &syserrortext within the same session.

Now I have &syscc that won't capture errors, &syserrortext that captures but cannot be reset, is there an alternate way to handle this?

1 Answers

Per the documentation of &SYSCC:

Note: When the ERRORCHECK= SAS system option is set at NORMAL, the value of SYSCC will be 0 even if an error exists in a LIBNAME or FILENAME statement, or in a LOCK statement in SAS/SHARE software. The value of SYSCC will also be 0 when the %INCLUDE statement fails due to a nonexistent file. For more information, see the ERRORCHECK= System Option in SAS System Options: Reference.

That reference page includes:

STRICT

specifies to place the SAS program into syntax-check mode when an error occurs in a LIBNAME or FILENAME statement, or in a LOCK statement in SAS/SHARE software. If the ERRORABEND system option is set and an error occurs in either a LIBNAME or FILENAME statement, SAS terminates. In addition, SAS terminates when a %INCLUDE statement fails due to a non-existent file.

See this example code:

%macro errvars;
 %put &=syscc;
 %put &=sysrc;
 %put &=syserrortext;
%mend errvars;

%errvars;
%include "c:\doesnotexist.txt";
%errvars;
* Shows SYSCC=0;
options errorcheck=strict;
%include "c:\doesnotexist.txt";
%errvars;
* Shows SYSCC=1012;

Log:

 75         %errvars;
 SYSCC=0
 SYSRC=0
 SYSERRORTEXT=
 76         %include "c:\doesnotexist.txt";
 WARNING: Physical file does not exist, c:\doesnotexist.txt.
 ERROR: Cannot open %INCLUDE file c:\doesnotexist.txt.
 77         %errvars;
 SYSCC=0
 SYSRC=0
 SYSERRORTEXT=Cannot open %INCLUDE file c:\doesnotexist.txt.
 78         * Shows SYSCC=0;
 79         options errorcheck=strict;
 80         %include "c:\doesnotexist.txt";
 WARNING: Physical file does not exist, c:\doesnotexist.txt.
 ERROR: Cannot open %INCLUDE file c:\doesnotexist.txt.
 81         %errvars;
 SYSCC=1012
 SYSRC=0
 SYSERRORTEXT=Cannot open %INCLUDE file c:\doesnotexist.txt.
Related