DO_OVER Method

Traverses a list of duplicate keys in the hash object.

Applies to: Hash object

Syntax

object.DO_OVER (KEY:keyvalue);

Arguments

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.

Details

When a hash object has multiple values for a single key, you can use the DO_OVER method in an iterative DO loop to traverse the duplicate keys. The DO_OVER method reads the key on the first method call and continues to traverse the duplicate key list until the key reaches the end.
Note: If you switch the key in the middle of an iteration, you must use the RESET_DUP method to reset the pointer to the beginning of the list. Otherwise, SAS continues to use the first key.

Example

The following example creates a data set, dup, that contains duplicate keys. The DO_OVER and RESET_DUP methods are used to iterate through the duplicate keys.
data dup;
 length key data 8;
 input key data;
 datalines;
  1 10
  2 11
  1 15
  3 20
  2 16
  2 9
  3 100
  5 5
  1 5
  4 6
  5 99
;
run;

data _null_;
 length r 8;
 dcl hash h(dataset:'dup', multidata: 'y', ordered: 'y');
 h.definekey('key');
 h.definedata('key', 'data');
 h.definedone();

h.reset_dup();
key = 2;
do while(h.do_over(key:key) eq 0);
  put key= data=;
end;

key = 3;
do while(h.do_over(key:key) eq 0);
  put key= data=;
end;

key = 2;
do while(h.do_over(key:key) eq 0);
  put key= data=;
end;

run;
The following lines are written to the SAS log.
key=2 data=11
key=2 data=16
key=2 data=9
key=3 data=20
key=3 data=100
key=2 data=11
key=2 data=16
key=2 data=9

See Also

Methods: