Adding New Observations to the Master Data Set
You can use the MODIFY statement to add observations to an existing master data set. If
the transaction data set contains an observation that does not match an observation in the
master data set, then SAS enables you to write a new observation to the master data set if
you use an explicit OUTPUT statement in your program. When you specify an explicit
OUTPUT statement, you must also specify a REPLACE statement if you want to replace
observations in place. All new observations append to the end of the master data set.
Checking for Program Errors
You can use the _IORC_ automatic variable for error checking in your DATA step
program. The _IORC_ automatic variable contains the return code for each I/O operation
that the MODIFY statement attempts to perform.
The best way to test the values of _IORC_ is with the mnemonic codes that are provided
by the SYSRC autocall macro. Each mnemonic code describes one condition. The
mnemonics provide an easy method for testing problems in a DATA step program. The
following is a partial list of codes:
specifies that the transaction data set observation does not exist in the master data set
(used only with MODIFY and BY statements). If consecutive observations with
different BY values do not find a match in the master data set, then both of them
specifies that multiple transaction data set observations with a given BY value do not
exist in the master data set (used only with MODIFY and BY statements). If
consecutive observations with the same BY values do not find a match in the master
data set, then the first observation returns _DSENMR and the subsequent
observations return _DSEMTR.
specifies that no matching observation was found.
specifies that the observation was located in the master data set and indicates that the
MODIFY statement executed successfully.
The program in this section updates values in a master data set with values from a
transaction data set. If a transaction does not exist in the master data set, then the
program adds the transaction to the master data set.
In this example, a warehouse received a shipment of new items, and the
INVENTORY_TOOL master data set must be modified to reflect the changes. The
master data set contains a complete list of the inventory items. The transaction data set
contains items that are on the master inventory as well as new inventory items.
The following program creates the ADD_INVENTORY transaction data set, which
contains items for updating the master data set. The PartNumber variable contains the
part number for the item and corresponds to PartNumber in the INVENTORY_TOOL
data set. The Description variable names the item. The NewStock variable contains the
Modifying a Master Data Set with Observations from a Transaction Data Set 339