As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 11 Hash Index Join.sas
1 /* "Chapter 11 Hash Index Join.sas" from the SAS Press book
2  Data Management Solutions Using SAS Hash Table Operations:
3  A Business Intelligence Case Study
4 */
5 
6 %let comp_keys = Game_SK Inning Top_Bot AB_Number ;
7 %let data_vars = Batter_ID Is_A_Hit Result ;
8 %let data_list = %sysfunc (tranwrd (&data_vars, %str( ), %str(,))) ;
9 
10 data Join_Runs_AtBats_RID (drop = _: Runs) ;
11  if _n_ = 1 then do ;
12  dcl hash h (multidata:"Y", ordered:"A") ;
13  do _k = 1 to countw ("&comp_keys") ;
14  h.defineKey (scan ("&comp_keys", _k)) ;
15  end ;
16  h.defineData ("RID") ;
17  h.defineDone() ;
18  do RID = 1 by 1 until (LR) ;
19  set dw.AtBats (keep=&comp_keys Runs where=(Runs)) end = LR ;
20  h.add() ;
21  end ;
22  end ;
23  set dw.Runs ;
24  call missing (&data_list, _count) ;
25  do while (h.do_over() = 0) ;
26  _count = sum (_count, 1) ;
27  set dw.Runs point = RID ;
28  output ;
29  end ;
30  if not _count then output ;
31 run ;