Chapter Contents

Previous

Next
SAS Component Language: Reference

Using SAS System Return Codes

The value of a SAS system return code can be interpreted as:
0 The operation was completed successfully.
>0 An error condition was detected during the operation.
<0 The operation was completed, but a warning or a note was generated.

Not all SCL functions that return completion code values return SAS system return codes. Some functions return a completion code value that reports the success or failure of the requested operation (usually 1 for success or 0 for failure). These values are referred to in this book simply as return codes because they do not have the special property of SAS system return codes described above.


Obtaining a SAS System Return Code

Some functions -- notably OPEN, DOPEN, FOPEN, and MOPEN -- return values other than SAS system return codes. For these functions, use the SYSRC function to obtain the SAS system return code for the operation. SAS software retains the value of the return code for the most recent warning or error condition, and the SYSRC function reads the stored value.

The following example assigns the SAS system return code to the variable ERRNUM if the OPEN operation fails:

tableid=open('prices','I');
if tableid=0 then do;
   errnum=sysrc();
   put "Open failed" errnum;
end;

Note:   If you call the SYSRC function after executing a function that returns a SAS system return code, the value that the SYSRC function returns is the same as the value that the original function returned.  [cautionend]


Obtaining the Message for a SAS System Return Code

In many cases, knowing the value of a SAS system return code enables you to determine whether an operation succeeded or failed. However, in some cases warning messages can be useful for informing users of special situations that may need to be corrected.

You can use the SYSMSG function to return the text of the error message that was produced by the most recent SCL warning or error.

For example, the following statements display the SAS system message for the error condition that is produced when the FETCH function returns a nonzero return code:

rc=fetch(dsid);
if rc then _msg_=sysmsg();

The message string that SYSMSG() returns is reset to blank after each call to SYSMSG() until the next error or warning condition occurs.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.