As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 5 GeneratePlayerCandidates.sas
1 /* "Chapter 5 GeneratePlayerCandidates.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 first_names;
7  /* SRC: https://www.ssa.gov/oact/babynames/decades/century.html */
8  infile datalines;
9  informat First_Name $12.;
10  input First_Name $;
11  First_Name = propcase(First_Name);
12  n + 1;
13  datalines;
14 James
15 John
16 Robert
17 Michael
18 William
19 David
20 Richard
21 Joseph
22 Thomas
23 Charles
24 Christopher
25 Daniel
26 Matthew
27 Anthony
28 Donald
29 Mark
30 Paul
31 Steven
32 George
33 Kenneth
34 Andrew
35 Joshua
36 Edward
37 Brian
38 Kevin
39 Ronald
40 Timothy
41 Jason
42 Jeffrey
43 Ryan
44 Gary
45 Jacoby
46 Nicholas
47 Eric
48 Stephen
49 Jonathan
50 Larry
51 Scott
52 Frank
53 Justin
54 Brandon
55 Raymond
56 Gregory
57 Samuel
58 Benjamin
59 Patrick
60 Jack
61 Alexander
62 Dennis
63 Jerry
64 Tyler
65 Aaron
66 Henry
67 Douglas
68 Peter
69 Jose
70 Adam
71 Zachary
72 Walter
73 Nathan
74 Harold
75 Kyle
76 Carl
77 Arthur
78 Gerald
79 Roger
80 Keith
81 Jeremy
82 Lawrence
83 Terry
84 Sean
85 Albert
86 Joe
87 Christian
88 Austin
89 Willie
90 Jesse
91 Ethan
92 Billy
93 Bruce
94 Bryan
95 Ralph
96 Roy
97 Jordan
98 Eugene
99 Wayne
100 Louis
101 Dylan
102 Alan
103 Juan
104 Noah
105 Russell
106 Harry
107 Randy
108 Philip
109 Vincent
110 Gabriel
111 Bobby
112 Johnny
113 Howard
114 ;
115 data last_names;
116  /* SRC: http://names.mongabay.com/most_common_surnames.htm */
117  infile datalines;
118  informat Last_Name $12.;
119  input Last_Name $;
120  Last_Name = propcase(Last_Name);
121  n + 1;
122 datalines;
123 SMITH
124 JOHNSON
125 WILLIAMS
126 JONES
127 BROWN
128 DAVIS
129 MILLER
130 WILSON
131 MOORE
132 TAYLOR
133 ANDERSON
134 THOMAS
135 JACKSON
136 WHITE
137 HARRIS
138 MARTIN
139 THOMPSON
140 GARCIA
141 MARTINEZ
142 ROBINSON
143 CLARK
144 RODRIGUEZ
145 LEWIS
146 LEE
147 WALKER
148 HALL
149 ALLEN
150 YOUNG
151 HERNANDEZ
152 KING
153 WRIGHT
154 LOPEZ
155 HILL
156 SCOTT
157 GREEN
158 ADAMS
159 BAKER
160 GONZALEZ
161 NELSON
162 CARTER
163 MITCHELL
164 PEREZ
165 ROBERTS
166 TURNER
167 PHILLIPS
168 CAMPBELL
169 PARKER
170 EVANS
171 EDWARDS
172 COLLINS
173 STEWART
174 SANCHEZ
175 MORRIS
176 ROGERS
177 REED
178 COOK
179 MORGAN
180 BELL
181 MURPHY
182 BAILEY
183 RIVERA
184 COOPER
185 RICHARDSON
186 COX
187 HOWARD
188 WARD
189 TORRES
190 PETERSON
191 GRAY
192 RAMIREZ
193 JAMES
194 WATSON
195 BROOKS
196 KELLY
197 SANDERS
198 PRICE
199 BENNETT
200 WOOD
201 BARNES
202 ROSS
203 HENDERSON
204 COLEMAN
205 JENKINS
206 PERRY
207 POWELL
208 LONG
209 PATTERSON
210 HUGHES
211 FLORES
212 WASHINGTON
213 BUTLER
214 SIMMONS
215 FOSTER
216 GONZALES
217 BRYANT
218 ALEXANDER
219 RUSSELL
220 GRIFFIN
221 DIAZ
222 HAYES
223 ;
224 data _null_;
225  if 0 then set template.player_candidates;
226  retain Player_ID 10000 Team_SK 0;
227  declare hash positionsDist();
228  rc = positionsDist.defineKey("Index");
229  rc = positionsDist.defineData("Index","Position_Code","Count");
230  rc = positionsDist.defineDone();
231  lr = 0;
232  Index = 0;
233  do until(lr);
234  set bizarro.positions end=lr;
235  do i = 1 to Count;
236  Index + 1;
237  rc = positionsDist.add();
238  end;
239  end;
240  rc = positionsDist.output(dataset:"positions");
241 
242  declare hash fname(dataset: "first_names");
243  rc = fname.defineKey("First_Name");
244  rc = fname.defineData("First_Name");
245  rc = fname.defineDone();
246  declare hiter first_iter("fname");
247 
248  declare hash lname(dataset: "last_names");
249  rc = lname.defineKey("Last_Name");
250  rc = lname.defineData("Last_Name");
251  rc = lname.defineDone();
252  declare hiter last_iter("lname");
253 
254  declare hash players();
255  rc = players.defineKey("Arbtrary","First_Name","Last_Name");
256  rc = players.defineData("Player_ID","Team_SK","First_Name","Last_Name"
257  ,"Position_Code","Bats","Throws");
258  rc = players.defineDone();
259 
260  Arbtrary = 0;
261  do frc = first_iter.first() by 0 while(frc = 0);
262  do lrc = last_iter.first() by 0 while(lrc = 0);
263  Arbitrary + 1;
264  positionsDist.find(Key:ceil(uniform(&seed2)*&nPlayersPerTeam));
265  Player_ID + ceil(uniform(&seed3)*9);
266  random = uniform(&seed10);
267  if random le .1 then Bats = "S";
268  else if random le .35 then Bats = "L";
269  else Bats = "R";
270  if uniform(&seed11) le .3 then Throws = "L";
271  else Throws = "R";
272  players.add();
273  lrc = last_iter.next();
274  end;
275  frc = first_iter.next();
276  end;
277  players.output(dataset:"bizarro.player_candidates");
278 
279 run;