Chapter Contents |
Previous |
Next |
REPLACE |
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 |
Arguments |
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:
|
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.