The SYSERR automatic macro variable is used in this example to display a message in the SAS Log when an error condition is met.
When writing programs, you can use SYSERR as a condition for determining what action to take when the program encounters an error. Using SYSERR is also helpful in debugging a program. You can assign output messages to be written to the SAS Log to draw your attention to the problem area in the program.
%put "<<System Error code" &syserr;
The SYSERR automatic macro variable is documented in the SAS Macro Language: Reference. The values of SYSERR are:
0 Execution completed successfully and without warning 1 Execution was canceled by user with a RUN CANCEL statement 2 Execution was canceled by a user with an ATTN or Break command 3 An error in a program run in batch or non-interactve mode caused SAS to enter syntax-check mode 4 Execution completed successfully but with warning messages >4 An error occurred. The value returned is procedure-dependent
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
In each procedure or DATA step below, the value of SYSERR is captured and written to the SAS Log. The value of SYSERR is reset at each step boundary. Using SYSERR is a quick way to determine whether your program ran successfully. In the case below, a SYSERR value of 4 is returned because PROC APPEND was trying to append duplicate values to the data set specified with the BASE= option.
options ls=79 nodate nocenter;
/* Specify the path to the data */
libname source '.';
/* Create test data for BASE= data set */
data source.acct_nums;
do i = 1 to 1000;
id=i;
output;
end;
run;
%put <<System Error code" &syserr;
/* Create a unique index */
proc datasets lib=source nolist;
modify acct_nums;
index create id / unique nomiss updatecentiles=always;
run;
quit;
/* Create test data for the DATA= data set */
data source.acct_nums2;
do i = 77 to 78;
id=i;
output;
end;
run;
%put "<<System Error Code" &syserr;
proc append base=source.acct_nums data=source.acct_nums2;
run;
%put "<<System Error Code" &syserr;
/* Create test data for DATA= data set */
data source.acct_nums2;
do i = 1001 to 1002;
id=i;
output;
end;
run;
%put "<<System Error Code" &syserr;
/* No warning */
proc append base=source.acct_nums data=source.acct_nums2;
run;
%put "<<System Error Code" &syserr;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
1 options ls=79 nodate nocenter; 2 3 /* Specify the path to the data */ 4 libname source '.'; NOTE: Libref SOURCE was successfully assigned as follows: Engine: V9 Physical Name: C:\test 5 6 /* Create test data for BASE= data set */ 7 data source.acct_nums; 8 do i = 1 to 1000; 9 id=i; 10 output; 11 end; 12 run; NOTE: The data set SOURCE.ACCT_NUMS has 1000 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 13 %put "<<System Error code" &syserr; "<<System Error code" 0 14 15 /* Create a unique index */ 16 proc datasets lib=source nolist; NOTE: Writing HTML Body file: sashtml.htm 17 modify acct_nums; 18 index create id / unique nomiss updatecentiles=always; NOTE: Simple index id has been defined. 19 run; NOTE: MODIFY was successful for SOURCE.ACCT_NUMS.DATA. 20 quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.77 seconds cpu time 0.12 seconds 21 22 /* Create test data for the DATA= data set */ 23 data source.acct_nums2; 24 do i = 77 to 78; 25 id=i; 26 output; 27 end; 28 run; NOTE: The data set SOURCE.ACCT_NUMS2 has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 29 %put "<<System Error Code" &syserr; "<<System Error Code" 0 30 31 proc append base=source.acct_nums data=source.acct_nums2; 32 run; NOTE: Appending SOURCE.ACCT_NUMS2 to SOURCE.ACCT_NUMS. WARNING: Duplicate values not allowed on index id for file ACCT_NUMS, 2 observations rejected. NOTE: There were 2 observations read from the data set SOURCE.ACCT_NUMS2. NOTE: 0 observations added. NOTE: The data set SOURCE.ACCT_NUMS has 1000 observations and 2 variables. NOTE: PROCEDURE APPEND used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 33 %put "<<System Error Code" &syserr; "<<System Error Code" 4 34 35 /* Create test data for DATA= data set */ 36 data source.acct_nums2; 37 do i = 1001 to 1002; 38 id=i; 39 output; 40 end; 41 run; NOTE: The data set SOURCE.ACCT_NUMS2 has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 42 %put "<<System Error Code" &syserr; "<<System Error Code" 0 43 44 /* No warning */ 45 proc append base=source.acct_nums data=source.acct_nums2; 46 run; NOTE: Appending SOURCE.ACCT_NUMS2 to SOURCE.ACCT_NUMS. NOTE: There were 2 observations read from the data set SOURCE.ACCT_NUMS2. NOTE: 2 observations added. NOTE: The data set SOURCE.ACCT_NUMS has 1002 observations and 2 variables. NOTE: PROCEDURE APPEND used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 47 %put "<<System Error Code" &syserr; "<<System Error Code" 0
Type: | Sample |
Date Modified: | 2012-02-20 15:46:42 |
Date Created: | 2011-12-14 13:21:17 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | Base SAS | z/OS | 9.21_M3 | 9.2 TS2M3 | ||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows XP 64-bit Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft® Windows® for x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 Datacenter Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 Enterprise Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 Standard Edition | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2003 for x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2008 | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows Server 2008 for x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Microsoft Windows XP Professional | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Enterprise 32 bit | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Enterprise x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Home Premium 32 bit | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Home Premium x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Professional 32 bit | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Professional x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Ultimate 32 bit | 9.21_M3 | 9.2 TS2M3 | ||||
Windows 7 Ultimate x64 | 9.21_M3 | 9.2 TS2M3 | ||||
Windows Vista | 9.21_M3 | 9.2 TS2M3 | ||||
Windows Vista for x64 | 9.21_M3 | 9.2 TS2M3 | ||||
64-bit Enabled AIX | 9.21_M3 | 9.2 TS2M3 | ||||
64-bit Enabled HP-UX | 9.21_M3 | 9.2 TS2M3 | ||||
64-bit Enabled Solaris | 9.21_M3 | 9.2 TS2M3 | ||||
HP-UX IPF | 9.21_M3 | 9.2 TS2M3 | ||||
Linux | 9.21_M3 | 9.2 TS2M3 | ||||
Linux for x64 | 9.21_M3 | 9.2 TS2M3 | ||||
OpenVMS on HP Integrity | 9.21_M3 | 9.2 TS2M3 | ||||
Solaris for x64 | 9.21_M3 | 9.2 TS2M3 |