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

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

  • Using an OUTPUT, REPLACE, or REMOVE statement overrides the default write action at the end of a DATA step. (OUTPUT is the default action; REPLACE becomes the default action when a MODIFY statement is used.) If you use any of these statements in a DATA step, you must explicitly program output of a new observation for the step.

  • The OUTPUT, REPLACE, and REMOVE statements are independent of each other. More than one statement can apply to the same observation, as long as the sequence is logical.

  • If both an OUTPUT and a REPLACE or REMOVE statement execute on a given observation, perform the OUTPUT action last to keep the position of the observation pointer correct.

  • REPLACE writes the observation to the same physical location, while OUTPUT writes a new observation to the end of the data set.

  • REPLACE can appear only in a DATA step that contains a MODIFY statement. You can use OUTPUT with or without MODIFY.

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 on page 1307

  • OUTPUT Statement on page 1339

  • REMOVE Statement on page 1375




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net