Previous Page | Next Page

Updating SAS Data Sets

Understanding the UPDATE Statement

When you update, you work with two SAS data sets. The data set that contains the original information is the master data set. The data set that contains the new information is the transaction data set. Many applications, such as maintaining mailing lists and inventories, call for periodic updates of information.

In a DATA step, the UPDATE statement reads observations from the transaction data set and updates corresponding observations (observations with the same value of all BY variables) from the master data set. All nonmissing values for variables in the transaction data set replace the corresponding values that are read from the master data set. SAS writes the modified observations to the data set that you name in the DATA statement without modifying either the master or the transaction data set.

The general form of the UPDATE statement is

UPDATE master-SAS-data-set transaction-SAS-data-set;
BY identifier-list;

where

master-SAS-data-set

is the SAS data set containing information you want to update.

transaction-SAS-data-set

is the SAS data set containing information with which you want to update the master data set.

identifier-list

is the list of BY variables by which you identify corresponding observations.

If the master data set contains an observation that does not correspond to an observation in the transaction data set, the DATA step writes that observation to the new data set without modification. An observation from the transaction data set that does not correspond to any observation in the master data set becomes the basis for a new observation. The new observation may be modified by other observations from the transaction data set before it is written to the new data set.

Previous Page | Next Page | Top of Page