As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 8 Multiple Medians.sas
1 /* "Chapter 8 Multiple Medians.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 Medians;
7  length Type $12;
8  keep Type Distance Count;
9  format Count comma9.;
10 
11  dcl hash h();
12  h = _new_ hash(dataset:"dw.AtBats(where=(Result='Single'))"
13  ,multidata:"Y",ordered:"A");
14  h.defineKey("Distance");
15  h.defineDone();
16  type = "Singles";
17  dcl hiter iter;
18  iter = _new_ hiter("h");
19  link getMedians;
20 
21  h = _new_ hash(dataset:"dw.AtBats (where=(Result='Double'))"
22  ,multidata:"Y",ordered:"A");
23  h.defineKey("Distance");
24  h.defineDone();
25  type = "Doubles";
26  iter = _new_ hiter("h");
27  link getMedians;
28 
29  h = _new_ hash(dataset:"dw.AtBats(where=(Result='Triple'))"
30  ,multidata:"Y",ordered:"A");
31  h.defineKey("Distance");
32  h.defineDone();
33  type = "Triples";
34  iter = _new_ hiter("h");
35  link getMedians;
36 
37  h = _new_ hash(dataset:"dw.AtBats(where=(Result='Home Run'))"
38  ,multidata:"Y",ordered:"A");
39  h.defineKey("Distance");
40  h.defineDone();
41  type = "Home Runs";
42  iter = _new_ hiter("h");
43  link getMedians;
44 
45  stop;
46  getMedians:
47  Count = h.num_items;
48  iter.first();
49  do i = 1 to .5*Count - 1;
50  iter.next();
51  end;
52  /* could add logic here to interpolate if needed */
53  output;
54  h.delete();
55  return;
56 
57  set dw.AtBats(keep=Distance);
58 run;