You can use the CHECK
method in one of two ways to find data in a hash object.
You can specify the
key, and then use the CHECK method as shown in the following code:
data _null_;
length k $8;
length d $12;
/* Declare hash object and key and data variable names */
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;
/* Define constant key and data values and add to hash object */
rc = h.add(key: 'Joyce', data: 'Ulysses');
/* Verify that JOYCE key is in hash object */
k = 'Joyce';
rc = h.check();
if (rc = 0) then
put 'Key is in the hash object.';
run;
Alternatively, you can
use a shortcut and specify the key directly in the CHECK method call
as shown in the following code:
data _null_;
length k $8;
length d $12;
/* Declare hash object and key and data variable names */
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;
/* Define constant key and data values and add to hash object */
rc = h.add(key: 'Joyce', data: 'Ulysses');
/* Verify that JOYCE key is in hash object */
rc = h.check(key: 'Joyce');
if (rc =0) then
put 'Key is in the hash object.';
run;