EQUALS Method

Determines whether two hash objects are equal.

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 a hash object.

HASH:'object'

specifies the name of the second hash object that is compared to the first hash object.

RESULT: variable name

specifies the name of a numeric variable name to hold the result. If the hash objects are equal, the result variable is 1. Otherwise, the result variable is zero.

Details

The following example compares H1 to H2 hash objects:
 length eq k 8;
 declare hash h1();
 h1.defineKey('k');
 h1.defineDone();

 declare hash h2();
 h2.defineKey('k');
 h2.defineDone();

 rc = h1.equals(hash: 'h2', result: eq);
 if eq then
    put 'hash objects equal';
 else
    put 'hash objects not equal';
The two hash objects are defined as equal when all of the following conditions occur:
  • Both hash objects are the same size—that is, the HASHEXP sizes are equal.
  • Both hash objects have the same number of items—that is, H1.NUM_ITEMS = H2.NUM_ITEMS.
  • Both hash objects have the same key and data structure.
  • In an unordered iteration over H1 and H2 hash objects, each successive record from H1 has the same key and data fields as the corresponding record in H2—that is, each record is in the same position in each hash object and each such record is identical to the corresponding record in the other hash object.

Example: Comparing Two Hash Objects

In the following example, the first return call to EQUALS returns a nonzero value and the second return call returns a zero value.
data x;
   length k eq 8;
   declare hash h1();
   h1.defineKey('k');
   h1.defineDone();

   declare hash h2();
   h2.defineKey('k');
   h2.defineDone();

   k = 99;
   h1.add();
   h2.add();
   rc = h1.equals(hash: 'h2', result: eq);
   put eq=;

   k = 100;
   h2.replace();

   rc = h1.equals(hash: 'h2', result: eq);
   put eq=;

 run;