Previous Page | Next Page

Statements

REPLACE Statement



Replaces an observation in the same location.
Valid: in a DATA step
Category: Action
Type: Executable
Restriction: Use only with a MODIFY statement.

Syntax
Without Arguments
Arguments
Details
Comparisons
Examples
See Also

Syntax

REPLACE <data-set-name-1><. . .data-set-name-n>;


Without Arguments

If you specify no argument, the REPLACE statement writes the current observation to the same physical location from which it was read in all data sets that are named in the DATA statement.


Arguments

data-set-name

specifies the data set to which the observation is written.

Requirement: The data set name must also appear in the DATA statement and in one or more MODIFY statements.

Details

Using an explicit REPLACE statement overrides the default replacement of observations. If a DATA step contains a REPLACE statement, explicitly program all output for the step.


Comparisons


Examples

This example updates phone numbers in data set MASTER with values in data set TRANS. It also adds one new observation at the end of data set MASTER. The SYSRC autocall macro tests the value of _IORC_ for each attempted retrieval from MASTER. (SYSRC is part of the SAS autocall macro library.) The resulting SAS data set appears after the code:

data master;
   input FirstName $ id $ PhoneNumber;
   datalines;
Kevin ABCjkh 904
Sandi defsns 905
Terry ghitDP 951
Jason jklJWM 962
;

data trans;
   input FirstName $ id $ PhoneNumber;
   datalines;
. ABCjkh 2904
. defsns 2905
Madeline mnombt 2983
;

data master;
   modify master trans;
   by id;
      /* obs found in master  */
      /* change info, replace */
   if _iorc_ = %sysrc(_sok) then replace;

      /* obs not in master    */
   else if _iorc_ = %sysrc(_dsenmr) then 
      do; 
         /* reset _error_        */
         _error_=0;       
         /* reset _iorc_         */
         _iorc_=0;  
         /* output obs to master */
      output;  
      end;
run;

proc print data=master;
   title 'MASTER with New Phone Numbers';
run;

                 MASTER with New Phone Numbers                 3

                     First                  Phone
              OBS    Name          id      Number

               1     Kevin       ABCjkh     2904 
               2     Sandi       defsns     2905 
               3     Terry       ghitDP      951 
               4     Jason       jklJWM      962 
               5     Madeline    mnombt     2983 

See Also

Statements:

MODIFY Statement

OUTPUT Statement

REMOVE Statement

Previous Page | Next Page | Top of Page