O'Reilly logo

SAS 9.4 Language Reference, 6th Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Output 21.18 Results of Updating a Master Data Set by Adding Observations
In the example, the DATA step updates the master data set, Inventory, based on values in
the transaction data set, Add_Inventory. The program uses the OUTPUT statement to
add observations 2, 3, and 5 to the master data set. It also uses the REPLACE statement
to update observations 1, 4, and 6 with new values for InStock. The _IORC_ automatic
variable is used for error checking.
For more information about _IORC_ and error checking, see “Error Checking When
Using Indexes to Randomly Access or Update Data” on page 507. For information
about using the SELECT statement conditionally, see “SELECT Statement” in SAS
Statements: Reference.
Error Checking When Using Indexes to Randomly
Access or Update Data
The Importance of Error Checking
When reading observations with the SET statement and KEY= option or with the
MODIFY statement, error checking is imperative for several reasons. The most
important reason is that these tools use nonsequential access methods. Therefore, there is
no guarantee that an observation will be located that satisfies the request. Error checking
enables you to direct execution to specific code paths, depending on the outcome of the
I/O operation. Your program continues execution for expected conditions and terminate
execution when unexpected results occur.
Error Checking When Using Indexes to Randomly Access or Update Data 507
Error-Checking Tools
Two tools have been created to make error checking easier when you use the MODIFY
statement or the SET statement with the KEY= option to process SAS data sets:
_IORC_ automatic variable
SYSRC autocall macro
_IORC_ is created automatically when you use the MODIFY statement or the SET
statement with KEY=. The value of _IORC_ is a numeric return code that indicates the
status of the I/O operation from the most recently executed MODIFY or SET statement
with KEY=. Checking the value of this variable enables you to detect abnormal I/O
conditions and to direct execution down specific code paths instead of having the
application terminate abnormally. For example, if the KEY= variable value does match
between two observations, you might want to combine them and output an observation.
If they do not match, however, you might want to only write a note to the log.
Because the values of the _IORC_ automatic variable are internal and subject to change,
the SYSRC macro was created to enable you to test for specific I/O conditions while
protecting your code from future changes in _IORC_ values. When you use SYSRC, you
can check the value of _IORC_ by specifying one of the mnemonics listed in the
following table.
Table 21.4 Most Common Mnemonic Values of _IORC_ for DATA Step Processing
Mnemonic Value Meaning of Return Code When Return Code Occurs
_DSENMR The Transaction data set
observation does not exist in the
Master data set.
MODIFY with BY is used and no
match occurs.
_DSEMTR Multiple Transaction data set
observations with the same BY
variable value do not exist in the
Master data set.
MODIFY with BY is used and
consecutive observations with the
same BY values do not find a
match in the first data set. In this
situation, the first observation that
fails to find a match returns
_DSENMR. The subsequent
observations return _DSEMTR.
_DSENOM No matching observation was
found in the Master data set.
SET or MODIFY with KEY=
finds no match.
_SENOCHN The output operation was
unsuccessful.
the KEY= option in a MODIFY
statement contains duplicate
values.
_SOK The I/O operation was successful. a match is found.
508 Chapter 21 Reading, Combining, and Modifying SAS Data Sets

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required