Replaces the data that is associated with the specified key with new data.
Applies to: | Hash object |
specifies whether the method succeeded or failed.
specifies the name of the hash object.
specifies the key value whose type must match the corresponding key variable that is specified in a DEFINEKEY method call.
keyvalue
”
pairs depends on the number of key variables that you define by using
the DEFINEKEY method.
Requirement | The KEY:keyvalue arguments must be in the same order as they were defined in the hash object because the hash object variable names are not specified. |
specifies the data value whose type must match the corresponding data variable that is specified in a DEFINEDATA method call.
datavalue
”
pairs depends on the number of data variables that you define by using
the DEFINEDATA method.
Requirement | The DATA:datavalue arguments must be in the same order as they were defined in the hash object because the hash object variable names are not specified. |
data work.show; length brd $10 plc $8; input brd plc; datalines; Terrier 2nd LabRetr 3rd Rottwlr 1st Collie bis ChinsCrstd 2nd Newfnlnd 3rd ;
proc print data=work.show; title 'SHOW Data Set Before Replace'; run;
data _null_;
length brd $12;
length plc $8;
if _N_ = 1 then do;
declare hash h(dataset: 'work.show');
rc = h.defineKey('brd');
rc = h.defineData('brd', 'plc');
rc = h.defineDone();
end;
/* Specify the key and new data value */
brd = 'Rottwlr';
plc = '2nd';
/* Call the REPLACE method to replace the data value */
rc = h.replace();
/* Write the hash table to the data set. */
rc = h.output(dataset: 'work.show');
run;
proc print data=work.show; title 'SHOW Data Set After Replace'; run;
data work.show;
length brd $10 plc $8;
input brd plc;
datalines;
Terrier 2nd
LabRetr 3rd
Rottwlr 1st
Collie bis
ChinsCrstd 2nd
Newfnlnd 3rd
;
data _null_;
length brd $12;
length plc $8;
if _N_ = 1 then do;
declare hash h(dataset: 'work.show');
rc = h.defineKey('brd');
rc = h.defineData('brd', 'plc');
rc = h.defineDone();
/* avoid uninitialized variable notes */
call missing(brd, plc);
end;
/* Specify the key and new data value in the REPLACE method */
rc = h.replace(key: 'Rottwlr', data: '2nd');
/* Write the hash table to the data set. */
rc = h.output(dataset: 'work.show');
run;
MULTIDATA: 'NO'
), whereas the
REPLACEDUP method is intended for use with hash tables that have multiple
data items for each key (MULTIDATA: 'YES'
).
In the SAS 9.4 release, if you call the REPLACE method and the hash
object was declared using the multidata:'y'
option,
then all data items for the current key are replaced with the new
data. In previous releases, no items are replaced and the new data
is added to the current key.For more information
about the MULTIDATA option, see DECLARE Statement, Hash and Hash Iterator Objects.