The REMOVE method deletes
both the key and the data from the hash object.
You can use the REMOVE
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 REMOVE method as shown in the following code:
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;
Alternatively, you can
use a shortcut and specify the key directly in the REMOVE method call
as shown in the following code:
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;
Note: The REMOVE method does not
modify the value of data variables. It only removes the value in the
hash object.
Note: If you specify
multidata:'y'
in the hash object constructor, the
REMOVE method will remove all data items for the specified key.