Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

FIND_NEXT Method



Sets the current list item to the next item in the current key's multiple item list and sets the data for the corresponding data variables.
Applies to: Hash object

Syntax
Arguments
Details
Examples
See Also

Syntax

rc=object.FIND_NEXT( );


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, an appropriate error message is printed to the log.

object

specifies the name of the hash object.


Details

The FIND method determines whether the key exists in the hash object. The HAS_NEXT method determines whether the key has multiple data items associated with it. When you have determined that the key has another data item, that data item can be retrieved by using the FIND_NEXT method, which sets the data variable to the value of the data item so that it is available for use after the method call. Once you are in the data item list, you can use the HAS_NEXT and FIND_NEXT methods to traverse the list.


Examples

This example uses the FIND_NEXT method to iterate through a data set where several keys have multiple data items. If a key has more than one data item, subsequent items are marked dup.

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
   ;

data _null_;
   dcl hash h(dataset:'dup', multidata: 'y');
   h.definekey('key');
   h.definedata('key', 'data');
   h.definedone();
   /* avoid uninitialized variable notes */
   call missing (key, data);

   do key = 1 to 5; 
      rc = h.find();
      if (rc = 0) then do;
         put key= data=;
         rc = h.find_next();
         do while(rc = 0);
            put 'dup ' key= data;
            rc = h.find_next();
         end;
      end;
   end;
 run;

The following lines are written to the SAS log.

Keys with Multiple Data Items

key=1 data=10
dup key=1 5
dup key=1 15
key=2 data=11
dup key=2 9
dup key=2 16
key=3 data=20
dup key=3 100
key=4 data=6
key=5 data=5
dup key=5 99

See Also

Methods:

FIND Method

FIND_PREV Method

HAS_NEXT Method

Non-Unique Key and Data Pairs in SAS Language Reference: Concepts

Previous Page | Next Page | Top of Page