Removes the data that is associated with the specified key from the hash object.
| 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
| Restriction | If an associated hash iterator is pointing to the keyvalue, then the REMOVE method will not remove the key or data from the hash object. An error message is issued. |
data _null_;
length k $8;
length d $12;
if _N_ = 1 then do;
declare hash h();
rc = h.defineKey('k');
rc = h.defineData('d');
rc = h.defineDone();
/* avoid uninitialized variable notes */
call missing(k, d);
end;
rc = h.add(key: 'Joyce', data: 'Ulysses');
/* Specify the key */
k = 'Joyce';
/* Use the REMOVE method to remove the key and data */
rc = h.remove();
if (rc = 0) then
put 'Key and data removed from the hash object.';
run;data _null_;
length k $8;
length d $12;
if _N_ = 1 then do;
declare hash h();
rc = h.defineKey('k');
rc = h.defineData('d');
rc = h.defineDone();
/* avoid uninitialized variable notes */
call missing(k, d);
end;
rc = h.add(key: 'Joyce', data: 'Ulysses');
rc = h.add(key: 'Homer', data: 'Iliad');
/* Specify the key in the REMOVE method parameter */
rc = h.remove(key: 'Homer');
if (rc =0) then
put 'Key and data removed from the hash object.';
run;multidata:'y' in
the hash object constructor, the REMOVE method will remove all data
items for the specified key.
/* Generate test data */
data x;
do k = 65 to 70;
d = byte (k);
output;
end;
run;
data _null_;
length k 8 d $1;
/* define the hash table and iterator */
declare hash H (dataset:'x', ordered:'a');
H.defineKey ('k');
H.defineData ('k', 'd');
H.defineDone ();
call missing (k,d);
declare hiter HI ('H');
/*Use this logic to remove a key in the hash object when an*/
/*iterator is pointing to that key. The NEXT method will*/
/*start at the first item in the hash object if it is called*/
/*without calling the FIRST method. */
do while (hi.next() = 0);
if flag then rc=h.remove(key:key);
if d = 'C' then do;
key=k;
flag=1;
end;
else flag=0;
end;
if flag then rc=h.remove(key:key);
rc = h.output(dataset: 'work.out');
stop;
run;
proc print;
run;
