Comparing Hash Objects
You can compare one hash object to another by using the EQUALS method. In the
following example, two hash objects are being compared. Note that the EQUALS
method has two argument tags. The HASH argument tag is the name of the second hash
object. The RESULTS argument tag is a numeric variable name that holds the result of
the comparison (1 if equal and zero if not equal).
length eq k 8;
declare hash myhash1();
myhash1.defineKey('k');
myhash1.defineDone();
declare hash myhash2();
myhash2.defineKey('k');
myhash2.defineDone();
rc = myhash1.equals(hash: 'myhash2', result: eq);
For more information, see the “EQUALS Method” in SAS Component Objects:
Reference.
Using Hash Object Attributes
You can use the DATA Step Component Interface to retrieve information from a hash
object using an attribute. Use the following syntax for an attribute:
attribute_value=obj.attribute_name;
There are two attributes available to use with hash objects. NUM_ITEMS returns the
number of items in a hash object and ITEM_SIZE returns the size (in bytes) of an item.
The following example retrieves the number of items in a hash object:
n = myhash.num_items;
The following example retrieves the size of an item in a hash object:
s = myhash.item_size;
You can obtain an idea of how much memory the hash object is using with the
ITEM_SIZE and NUM_ITEMS attributes. The ITEM_SIZE attribute does not reflect the
initial overhead that the hash object requires, nor does it take into account any necessary
internal alignments. Therefore, the use of ITEM_SIZE does not provide exact memory
usage, but it gives a good approximation.
For more information, see the “NUM_ITEMS Attribute ” in SAS Component Objects:
Reference and the “ITEM_SIZE Attribute” in SAS Component Objects: Reference.
530 Chapter 22 • Using DATA Step Component Objects