REPLACE Method
Replaces the data that is associated with the specified key with new data in the PROC FCMP hash object.
| Applies to: | PROC FCMP hash object |
|---|
Syntax
<DATA: datavalue-2>, ...>);
Arguments
rc
specifies whether the method succeeded or failed.
A return code of 0 indicates success; a nonzero value indicates failure. If you do not supply a return code variable for the method call and the method fails, an appropriate error message is written to the log.
object
specifies the name of the hash object.
KEY: keyvalue
specifies the key value whose type must match the corresponding key variable that is specified in a DEFINEKEY method call. The keyvalue must be a literal.
The number of “KEY: 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. |
|---|
DATA: datavalue
specifies the data value whose type must match the corresponding data variable that is specified in a DEFINEDATA method call. The datavalue must be a literal.
The number of “DATA: 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. |
|---|
Details
You can use the REPLACE method in one of two ways to replace data in a hash object.
You can define the key
and data item, and then use the REPLACE method to replace the data
as shown in the following code. In this example, the Place data
for the key 'Collie' is changed from 'BestInShow' to 'bis'.
data work.dogshow;
length breed $10 place $10;
input breed place;
datalines;
Terrier 2nd
Beagle 3rd
Rottweiler 1st
Collie BestInShow
Poodle 2nd
Boxer 3rd
;
proc fcmp;
length breed $10 place $10;
if _N_ = 1 then do;
declare hash h(dataset: 'work.dogshow');
rc = h.defineKey('breed');
rc = h.defineData('breed', 'place');
rc = h.defineDone();
end;
/* Specify the key and new data value */
breed = 'Collie';
place = 'bis';
/* Call the REPLACE method to replace the data value */
rc = h.replace();
run;
Alternatively, you can use a shortcut and specify the key and data directly in the REPLACE method call as shown in the following code.
data work.dogshow2;
length breed $10 place $10;
input breed place;
datalines;
Terrier 2nd
Beagle 3rd
Rottweiler 1st
Collie BestInShow
Poodle 2nd
Boxer 3rd
;
proc fcmp;
length breed $10 place $10;
if _N_ = 1 then do;
declare hash h(dataset:'work.dogshow2');
rc = h.defineKey('breed');
rc = h.defineData('breed', 'place');
rc = h.defineDone();
/* avoid uninitialized variable notes */
call missing(breed, place);
end;
/* Specify the key and new data value in the REPLACE method */
rc = h.replace(key: 'Collie', data: 'Collie', data: 'bis');
run;
See Also
-
Methods: