As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 4 Keeping Iterator in Table.sas
1 /* "Chapter 4 Keeping Iterator in Table.sas" from the SAS Press book
2  Data Management Solutions Using SAS Hash Table Operations:
3  A Business Intelligence Case Study
4 */
5 
6 data Forward (keep=ItemNo K D)
7  Backward (keep=ItemNo K D)
8  ;
9  dcl hash H (multidata:"Y", ordered:"N") ;
10  H.definekey ("K") ;
11  H.definedata ("D", "K") ;
12  H.definedone () ;
13  do K = 1, 2, 2, 3, 3, 3 ;
14  q + 1 ;
15  D = char ("ABCDEF", q) ;
16  H.add() ;
17  end ;
18  dcl hiter IH ("H") ;
19  do ItemNo = 1 to H.Num_Items ;
20  RC = IH.NEXT() ;
21  output Forward ;
22  end ;
23  /* end of forward loop */
24  do ItemNo = H.Num_Items - 1 by -1 to 1 ;
25  RC = IH.PREV() ;
26  output Backward ;
27  end ;
28 run ;