|Hash and Hash Iterator Object Language Elements|
|Applies to:||Hash object|
rc=object.REF(<KEY: keyvalue-1,..., KEY: keyvalue-n, DATA:
..., DATA: datavalue-n>);
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.
specifies the name of the hash object.
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.
specifies the data value whose type must match the corresponding data variable that is specified in a DEFINEDATA method call.
The number of "DATA: datavalue" pairs depends on the number of data variables that you define by using the DEFINEDATA method.
You can consolidate FIND and ADD methods into a single REF method. You can change the following code:
The REF method is useful for counting the number of occurrences of each key in a hash object. The REF method initializes the key summary for each key on the first ADD, and then changes the ADD for each subsequent FIND.
Note: The REF method sets the data variable to the value of the data item so that it is available for use after the method call.
For more information about key summaries, see SAS Language Reference: Concepts.
The following example uses the REF method for key summaries:
data keys; input key; datalines; 1 2 1 3 5 2 3 2 4 1 5 1 ; data count; length count key 8; keep key count; if _n_ = 1 then do; declare hash myhash(suminc: "count", ordered: "y"); declare hiter iter("myhash"); myhash.defineKey('key'); myhash.defineDone(); count = 1; end; do while (not done); set keys end=done; rc = myhash.ref(); end; rc = iter.first(); do while(rc = 0); rc = myhash.sum(sum: count); output; rc = iter.next(); end; stop; run;
The following lines are written to the SAS log.
Obs count key 1 4 1 2 3 2 3 2 3 4 1 4 5 2 5