As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 11 Pregrouped Aggregation.sas
1 /* "Chapter 11 Pregrouped Aggregation.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 Scores_grouped (keep = Game_SK Top_Bot Score) ;
7  if _n_ = 1 then do ;
8  dcl hash h (ordered:"A") ;
9  h.defineKey ("Top_Bot") ;
10  h.defineData ("Top_Bot", "Score") ;
11  h.defineDone () ;
12  dcl hiter ih ("h") ;
13  end ;
14  do until (last.Game_SK) ;
15  set Dw.Runs (keep = Game_SK Top_Bot) ;
16  by Game_SK ;
17  if h.find() ne 0 then Score = 1 ;
18  else Score + 1 ;
19  h.replace() ;
20  end ;
21  do while (ih.next() = 0) ;
22  output ;
23  end ;
24  h.clear() ;
25 run ;