REMOVEDUP Method
Removes the data that is associated with the specified key's current data item from the hash object.
| Applies to: | Hash object |
|---|
Syntax
Arguments
rc
specifies whether the method succeeded or failed.
A return code of zero indicates success; a nonzero value indicates failure. If you do not supply a return code variable for the method call and the method fails, then 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 number of “KEY: keyvalue” pairs depends on the number of key variables that you define by using the DEFINEKEY method.
| Restriction | If an associated hash iterator is pointing to the keyvalue, then the REMOVEDUP method does not remove the key or data from the hash object. An error message is issued. |
|---|
Details
The REMOVEDUP method deletes both the key and the data from the hash object.
You can use the REMOVEDUP method in one of two ways to remove the key and data in a hash object. You can specify the key, and then use the REMOVEDUP method. Alternatively, you can use a shortcut and specify the key directly in the REMOVEDUP method call.
Comparisons
The REMOVEDUP method removes the data that is associated with the specified key's current data item from the hash object. The REMOVE method removes the data that is associated with the specified key from the hash object.
Example: Removing Duplicate Items in Keys
This example creates a hash object where several keys have multiple data items. The second data item in the key is removed.
data testdup;
length key_id value 8;
input key_id value;
datalines;
1 10
2 11
1 15
3 20
2 16
2 9
3 100
5 5
1 5
4 6
5 99
;
data _null_;
length r 8;
dcl hash h(dataset:'testdup', multidata: 'y', ordered: 'y');
h.definekey('key_id');
h.definedata('key_id', 'value');
h.definedone();
call missing (key_id, value);
do key_id = 1 to 5;
rc = h.find();
if (rc = 0) then do;
h.has_next(result: r);
if (r ne 0) then do;
h.find_next();
h.removedup();
end;
end;
end;
dcl hiter i('h');
rc = i.first();
do while (rc = 0);
put key_id= value=;
rc = i.next();
end;
run;
The following lines are written to the SAS log:
key_id=1 value=10 key_id=1 value=5 key_id=2 value=11 key_id=2 value=9 key_id=3 value=20 key_id=4 value=6 key_id=5 value=5
See Also
-
Methods: