Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

CHECK Method



Checks whether the specified key is stored in the hash object.
Applies to: Hash object

Syntax
Arguments
Details
Comparisons
See Also

Syntax

rc=object.CHECK(<KEY: keyvalue-1,..., KEY: keyvalue-n>);


Arguments

rc

specifies whether the method succeeded or failed.

A return code of zero indicates success; a non-zero 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.


Details

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;


Comparisons

The CHECK method only returns a value that indicates whether the key is in the hash object. The data variable that is associated with the key is not updated. The FIND method also returns a value that indicates whether the key is in the hash object. However, if the key is in the hash object, then the FIND method also sets the data variable to the value of the data item so that it is available for use after the method call.


See Also

Methods:

FIND Method

DEFINEKEY Method

Previous Page | Next Page | Top of Page