-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbizarroball.sas
2385 lines (2253 loc) · 69.8 KB
/
bizarroball.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
@file
@brief Auto-generated file
@details The `build.sh` file in the https://github.com/allanbowe/bizarroball repo
is used to create this file.
@author Allan Bowe (derivative of work by Don Henderson and Paul Dorfman)
///@cond INTERNAL
**/
%let root=%sysfunc(pathname(sasuser)); /* change to another path as desired */
%*let root = /folders/myfolders/BizarroBall; /* use this for the University Edition */
options dlcreatedir;
libname bizarro "&root/Data";
libname DW "&root/DW";
libname template "&root/Data/Template";
/* SCD End Date - Used in Chapter 7 */
%let SCD_End_Date = '31DEC9999'd;
/* The following macro variables are only used in the programs/macros
to generate the sample Bizarro Ball data.
*/
/* Parameters for creating the data */
%let nTeamsPerLeague = 16;
%let seasonStartDate = 20MAR2017;
%let nWeeksSeason = %eval((&nTeamsPerLeague-1)*2);
%let nPlayersPerTeam = 25;
%let nBattersPerGame = 9;
/* Random Number Seeds */
%let seed1 = 54321; /* used in S0100 GenerateTeams.sas */
%let seed2 = 98765; /* used in S0300 GeneratePlayerCandidates.sas */
%let seed3 = 76543; /* used in S0300 GeneratePlayerCandidates.sas */
%let seed4 = 11; /* used in S0500 GenerateSchedule.sas */
%let seed5 = 9887; /* used in macro generatelinesups.sas */
%let seed6 = 9973; /* used in macro generatepitchandpadata.sas */
%let seed7 = 101; /* used in macro generatepitchandpadata.sas */
%let seed8 = 10663; /* used in macro generatepitchandpadata.sas */
%let seed9 = 10753; /* used in macro generatepitchandpadata.sas */
%let seed10 = 98999; /* used in S0300 GeneratePlayerCandidates.sas */
%let seed11 = 99223; /* used in S0300 GeneratePlayerCandidates.sas */
/* now include macros & datalines */
/* "createhash.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
%macro createHash
(lib = dw
,hashTable = hashTable
,metaData = template.Schema_Metadata
);
if 0 then set template.&hashTable;
dcl hash _&hashTable(dataset:"&lib..&hashtable"
,multidata:"Y"
,ordered:"A");
lr = 0;
do while(lr=0);
set &metadata end=lr;
where upcase(hashTable) = "%upcase(&hashTable)";
if is_a_key then _&hashTable..DefineKey(Column);
_&hashTable..DefineData(Column);
end;
_&hashTable..DefineDone();
%mend createHash;
/* "generatelineups.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
%macro generateLineUps
(from =
,nweeks =
);
%local to;
%let from = %sysfunc(inputn(&from,date9.));
%let to = %eval(&from + &nweeks*7 - 1);
%do date = &from %to &to;
data _null_;
retain Date &Date;
if 0 then
do; /* define vars to PDV */
set template.LineUps bizarro.Positions_Snowflake;
Away_SK = Team_SK;
Home_SK = Team_SK;
end; /* define vars to PDV */
/* load hash table with number of starters for each position */
declare hash positions(dataset:"bizarro.Positions");
positions.defineKey("Position_Grp_SK");
positions.defineData("Position_Grp_SK","Position_Code","Count","Starters");
positions.defineDone();
declare hiter positionIter("positions");
declare hash positions_snowflake(dataset:"bizarro.Positions_Snowflake",ordered:"A",multidata:"Y");
positions_snowflake.defineKey("Position_Grp_FK");
positions_snowflake.defineData("Position_Grp_FK","Position_Code");
positions_snowflake.defineDone();
declare hash LineUp(multidata:"Y");
rc = LineUp.defineKey("Game_SK","Team_SK");
rc = LineUp.defineData("Game_SK","Team_SK","Date","Batting_Order","Player_ID","First_Name","Last_Name","Position_Code","Bats","Throws");
rc = LineUp.defineDone();
declare hash players(dataset:"bizarro.Player_Candidates(where=(Team_SK))",ordered:"A",multidata:"Y");
rc = players.defineKey("Team_SK","Position_Code");
rc = players.defineData("Team_SK","Player_ID","First_Name","Last_Name","Bats","Throws");
rc = players.defineDone();
do while (lr = 0);
set bizarro.trades end = lr;
where trade_date le &date;
do while(players.do_over(Key:_team_sk,Key:_Position_Code) = 0);
if player_id = traded_id then
do; /* player traded - delete and re-add */
players.removeDup();
team_sk = traded_to;
Position_Code = _Position_Code;
players.add();
leave;
end;
end;
end;
declare hash games(dataset:"bizarro.Games(where=(date=&date))",multidata:"Y");
rc = games.defineKey("Date");
rc = games.defineData("Game_SK","Away_SK","Home_SK");
rc = games.defineDone();
games_rc = games.find(Key:&date);
do while (games_rc = 0);
do team_sk = away_sk, home_sk;
rc = positionIter.first();
P_Grp = Position_Code;
grp_rc = positions_snowflake.find(Key:Position_Grp_SK);
do while(rc=0);
prc = players.find(Key:Team_SK,Key:P_grp);
do while(prc = 0);
Batting_Order = uniform(&seed5*&date);
if divide(Starters,Count) gt Batting_Order then
do; /* select this player */
if position_code = "SP" then Batting_Order = 9;
rc = LineUp.add();
if grp_rc = 0 then grp_rc = positions_snowflake.find_next(Key:Position_Grp_SK);
Starters + (-1); /* need one less player */
end; /* select this player */
else if position_code ne "SP" then
do; /* pinch hitters and relief pitchers */
_position_code = position_code;
if position_code = 'RP' then Batting_Order = 1e6;
else
do;/* assign as a pinch hitter for the pitcher */
Batting_Order + 9;
Position_Code = 'PH';
end; /* assign as a pinch hitter for the pitcher */
LineUp.add();
position_code = _position_code;
end; /* pinch hitters and relief pitchers */
Count + (-1); /* regardless have one less player */
prc = players.find_next(Key:Team_SK,Key:P_grp);
end;
*if Position_Code = 'UT' then
do; /* add utility players as PHers */;
* Batting_Order = 9 + uniform(&seed5*&date);
*Position_Code = 'PH';
* LineUp.add();
*end; /* add utility players as PHers */;
rc=positionIter.next();
P_Grp = Position_Code;
grp_rc = positions_snowflake.find(Key:Position_Grp_SK);
end;
end;
games_rc = games.find_next();
end;
LineUp.output(dataset:"Lineups");
stop;
run;
proc sort data = lineups out = lineups;
by game_sk team_sk batting_order;
run;
%if %sysfunc(exist(bizarro.LineUps)) %then
%do; /* delete existing rows for these games */
proc sql;
delete from bizarro.Lineups
where Game_SK in (select distinct Game_SK from Lineups);
quit;
%end; /* delete existing rows for these games */
%else
%do; /* create the initial data set */
data bizarro.LineUps;
set Lineups(obs=0);
run;
%end; /* create initial data set */
data bizarro.LineUps(index=(LineUp=(Game_SK Team_SK)));
set bizarro.Lineups
LineUps(in = new);
drop Order;
by game_sk team_sk;
if first.team_sk then Order=0;
Order+1;
if batting_order ne int(batting_order) and new then batting_order = min(Order,9);
run;
%end;
%mend generateLineUps;
/* "generatepitchandpadata.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
%macro generatePitchAndPAData
(from =
,nweeks =
);
%local to;
%let from = %sysfunc(inputn(&from,date9.));
%let to = %eval(&from + &nweeks*7 - 1);
%do date = &from %to &to;
data _null_;
if 0 then set template.AtBats template.Pitches template.Runs;
retain Inning 1 Pitcher_ID . Date &date;
length data_to_load $16;
array runners(*) onFirst onSecond onThird;
if _n_ = 1 then
do; /* define the needed hash tables */
declare hash pitch_dist(ordered:"A");
rc = pitch_dist.DefineKey("Index");
rc = pitch_dist.DefineData("Index","Result","AB_Done","Is_An_Ab","Is_An_Out","Is_A_Hit","Is_An_OnBase"
,"Bases","Runners_Advance_Factor","Pitch_Distribution_SK");
rc = pitch_dist.DefineDone();
lr = 0;
do until(lr);
set bizarro.pitch_distribution end=lr;
do Index = From to To;
rc =pitch_dist.add();
end;
end;
lr=0;
declare hash hit_distance(dataset:"bizarro.hit_distance"
|| "(rename=(Pitch_Distribution_FK=Pitch_Distribution_SK))");
rc = hit_distance.DefineKey("Pitch_Distribution_SK");
rc = hit_distance.DefineData("MinDistance","MaxDistance");
rc = hit_distance.DefineDone();
declare hash batters(ordered:"A",multidata:"Y");
rc = batters.DefineKey("Top_Bot","Batting_Order");
rc = batters.DefineData("Team_SK","Top_Bot","Batter_ID","First_Name","Last_Name","Position_Code","Bats","Throws");
rc = batters.DefineDone();
declare hash pitchers(ordered:"D",multidata:"Y");
rc = pitchers.DefineKey("Top_Bot");
rc = pitchers.DefineData("Team_SK","Top_Bot","Pitcher_ID","First_Name","Last_Name","Position_Code","Pitcher_Bats","Pitcher_Throws");
rc = pitchers.DefineDone();
if exist("bizarro.Runs")
then data_to_load = "bizarro.Runs";
else data_to_load = "template.Runs";
declare hash facts_runs(dataset:data_to_load
,ordered:"A"
,multidata:"Y");
facts_runs.DefineKey("Date","Game_SK");
facts_runs.DefineData("Game_SK","Date","Batter_ID"
,"Inning","Top_Bot"
,"AB_Number","Runner_ID");
facts_runs.DefineDone();
if exist("bizarro.Pitches") then data_to_load = "bizarro.Pitches";
else data_to_load = "template.Pitches";
declare hash facts_pitches(dataset:data_to_load,ordered:"A",multidata:"Y");
facts_pitches.DefineKey("Date","Game_SK");
facts_pitches.DefineData("Game_SK","Date","Team_SK","Pitcher_ID","Pitcher_First_Name","Pitcher_Last_Name"
,"Pitcher_Bats","Pitcher_Throws","Pitcher_Type","Inning","Top_Bot","Result","AB_Number","Outs"
,"Balls","Strikes","Pitch_Number","Is_A_Ball","Is_A_Strike","onBase");
facts_pitches.DefineDone();
if exist("bizarro.AtBats") then data_to_load = "bizarro.AtBats";
else data_to_load = "template.AtBats";
declare hash facts_atbats(dataset:data_to_load,ordered:"A",multidata:"Y");
facts_atbats.DefineKey("Date","Game_SK");
facts_atbats.DefineData("Game_SK","Date","Time","League","Away_SK","Home_SK","Team_SK"
,"Batter_ID","First_Name","Last_Name","Position_Code","Inning"
,"Top_Bot","Bats","Throws","AB_Number","Result","Direction","Distance"
,"Outs","Balls","Strikes","onFirst","onSecond","onThird","onBase"
,"Left_On_Base","Runs","Is_An_AB","Is_An_Out","Is_A_Hit","Is_An_OnBase"
,"Bases","Number_of_Pitches");
facts_atbats.DefineDone();
end; /* define the needed hash tables */
if lr then
do; /* output the updated fact tables */
facts_runs.output(dataset:"bizarro.Runs");
facts_pitches.output(dataset:"bizarro.Pitches");
facts_atbats.output(dataset:"bizarro.AtBats");
end; /* output the updated fact tables */
set bizarro.games end=lr;
where date=&date;
League = League_SK; /* fix/hack for missed rename */
if game_sk ne lag(game_sk) then
do; /* delete existing rows for this game */
if facts_runs.check() = 0 then facts_runs.remove();
if facts_pitches.check() = 0 then facts_pitches.remove();
if facts_atbats.check() = 0 then facts_atbats.remove();
end; /* delete existing rows for this game */
/* load the batter data for this game */
rc = batters.clear();
rc = pitchers.clear();
Top_Bot = "T";
do team_sk = away_sk, home_sk;
do until(_iorc_ ne 0);
set bizarro.LineUps key = LineUp;
if _iorc_ = 0 then
do; /* row found and read */
rc = batters.add(Key:Top_Bot,Key:Batting_Order,Data:Team_SK,Data:Top_Bot,Data:Player_ID,Data:First_Name,Data:Last_Name,Data:Position_Code,Data:Bats,Data:Throws);
if Position_Code in ("SP" "RP") then rc = pitchers.add(Key:Top_Bot,Data:Team_SK,Data:Top_Bot,Data:Player_ID,Data:First_Name,Data:Last_Name,Data:Position_Code,Data:Bats,Data:Throws);
end; /* row found and read */
end;
Top_Bot = "B";
end;
Team_SK = .;
_error_ = 0; /* suppress the error message when the indexed read failed as expected */
array _halfInning(2) ab_t ab_b;
call missing(ab_t,ab_b);
do Inning = 1 to 9;
ab_index = 0;
do Top_Bot = "T", "B";
ab_index + 1;
rc = pitchers.find(key:Top_Bot);
rc = pitchers.has_next(result:not_last);
if inning ge 6 and not_last then
do;
rc=pitchers.removeDup();
pitchers.find(key:Top_Bot);
end;
Pitcher_First_Name = First_Name;
Pitcher_Last_Name = Last_Name;
Pitcher_Type = Position_Code;
outs = 0;
call missing(onFirst,onSecond,onThird);
do until(outs=3);
Is_An_Out = .;
Balls = 0;
Strikes = 0;
Pitch_Number = 0;
_halfInning(ab_index) + 1;
AB_Number = _halfInning(ab_index);
rc = batters.find(key:Top_Bot,Key:mod(AB_Number-1,&nBattersPerGame)+1);
rc = batters.has_next(result:not_last);
if mod(AB_Number,&nBattersPerGame)= 0 and inning ge 6 and not_last then
do;
rc=batters.removeDup();
batters.find(key:Top_Bot,Key:mod(AB_Number-1,&nBattersPerGame)+1);
end;
do until(AB_Done);
Pitch_Number+1;
Index = ceil(100*uniform(&seed6*&date));
rc = pitch_dist.find();
if not AB_Done then
do; /* continue the Plate Appearance */
call missing(Is_A_Ball,Is_A_Strike);
if Result = "Ball" then Is_A_Ball = 1;
else if find(Result,"strike","i") then Is_A_Strike = 1;
else if Result = "Foul" and Strikes lt 2 then Is_A_Strike = 1;
Balls + Is_A_Ball;
Strikes + Is_A_Strike;
facts_pitches.add();
AB_Done = (Balls = 4 or Strikes = 3);
if Balls = 4 then
do; /* set needed values for a walk */
Result = "Walk";
call missing(Is_An_AB,Is_An_Out,Is_A_Hit);
Bases = 1;
Runners_Advance_Factor = 1;
Is_An_OnBase = 1;
end; /* set needed values for a walk */
else if Strikes = 3 then
do; /* set needed values for a strikeout */
Result = "Strikeout";
Is_An_AB = 1;
Is_An_Out = 1;
Is_An_OnBase = 0;
call missing(Is_A_Hit,Bases);
end; /* set needed values for a walk */
end; /* continue the Plate Appearance */
else facts_pitches.add();
if ab_done then
do; /* create needed result fields */
call missing(MinDistance,MaxDistance,Direction,Distance);
if hit_distance.find()=0 then
do; /* calculate direction and distance */
Direction = ceil(18*uniform(&seed7*&date));
Distance = MinDistance + ceil((MaxDistance-MinDistance)*uniform(&seed8*&date));
end; /* calculate direction and distance */
onBase = 3 - nmiss(of runners(*));
Runs = 0;
if Bases then
do; /* advance runners */
Left_On_Base = 0;
Advance = Bases + (Runners_Advance_Factor > uniform(&seed9*Date));
do i = dim(runners) to 1 by -1;
if runners(i) then
do; /* advance runner on this base */
if i+Advance ge 4 then
do; /* runners scored */
Runs + 1;
Runner_ID = runners(i);
facts_runs.add();
end; /* runners scored */
else runners(i+Advance) = runners(i);
runners(i) = .;
end; /* advance runner on this base */
end;
if bases lt 4 then runners(bases) = batter_id;
else
do; /* runners scored */
Runs + 1;
Runner_ID = Batter_ID;
facts_runs.add();
end; /* runners scored */
end; /* advance runners */
else Left_On_Base = onBase;
Number_of_Pitches = Pitch_Number;
facts_atbats.add();
outs + Is_An_Out;
end; /* create needed result fields */
end; /* AB loop */
end; /* Outs Loop */
end; /* Innings Loop */
end; /* cheating a bit here - discuss with Paul */
run;
%end;
%mend generatePitchAndPAData;
/* "AtBats.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.ATBATS
(
Game_SK char(16) format=$HEX32. label = "Game Surrogate Key",
Date num format=YYMMDD10. label = "Game Date",
Time num format=TIMEAMPM8. label = "Game Time",
League num label = "League",
Home_SK num label = "Home Team Surrogate Key",
Away_SK num label = "Away Team Surrogate Key",
Team_SK num label = "Team Surrogate Key",
Batter_ID num label = "Batter ID",
First_Name char(12) label = "Batter First Name",
Last_Name char(12) label = "Batter Last Name",
Position_Code char(3) label "Batter Position",
Inning num label = "Inning",
Top_Bot char(1) label = "Which Half Inning",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R",
AB_Number num label = "At Bat Number in Game",
Result char(16) label = "Result of the At Bat",
Direction num label='Hit Direction',
Distance num label = 'Hit Distance',
Outs num label = "Number of Outs",
Balls num label = "Number of Balls",
Strikes num label = "Number of Strikes",
onFirst num label = "ID of Runner on First",
onSecond num label = "ID of Runner on Second",
onThird num label = "ID of Runner on Third",
onBase num label = "Number of Men on Base at Beginning of AB",
Left_On_Base num label = "Number of Men Left on Base at End of AB",
Runs num label = "Runs Scored",
Is_An_AB num label = "Counts as an AB",
Is_An_Out num label = "Is an Out",
Is_A_Hit num label = "Is a Hit",
Is_An_OnBase num label = "Counts as an On Base",
Bases num label = "Number of Bases for the Hit",
Number_of_Pitches num label = "Number of Pitches This AB"
);
quit;
/*******************************************************************
Datalines for CHAPTER8PARMFILE dataset
Generated by %mp_ds2cards()
Licensed under GNU, available on github.com/boemska/macrocore
********************************************************************/
data template.Chapter8parmfile ;
attrib
hashTable length= $32 label="Member Name"
Column length= $32 label="Column Name"
is_A_Key length= 8
;
infile cards dsd delimiter=',';
input
hashTable :$char.
Column :$char.
is_A_Key
;
datalines4;
BYDAYOFWEEK,DayOfWeek,1
BYDAYOFWEEK,PAs,0
BYDAYOFWEEK,AtBats,0
BYDAYOFWEEK,Hits,0
BYDAYOFWEEK,BA,0
BYDAYOFWEEK,OBP,0
BYDAYOFWEEK,SLG,0
BYDAYOFWEEK,OPS,0
BYDAYOFWEEK,_Bases,0
BYDAYOFWEEK,_Reached_Base,0
BYMONTH,Month,1
BYMONTH,PAs,0
BYMONTH,AtBats,0
BYMONTH,Hits,0
BYMONTH,BA,0
BYMONTH,OBP,0
BYMONTH,SLG,0
BYMONTH,OPS,0
BYMONTH,_Bases,0
BYMONTH,_Reached_Base,0
BYPLAYER,Last_Name,1
BYPLAYER,First_Name,1
BYPLAYER,Batter_ID,1
BYPLAYER,PAs,0
BYPLAYER,AtBats,0
BYPLAYER,Hits,0
BYPLAYER,BA,0
BYPLAYER,OBP,0
BYPLAYER,SLG,0
BYPLAYER,OPS,0
BYPLAYER,_Bases,0
BYPLAYER,_Reached_Base,0
BYPLAYERMONTH,Last_Name,1
BYPLAYERMONTH,First_Name,1
BYPLAYERMONTH,Batter_ID,1
BYPLAYERMONTH,Month,1
BYPLAYERMONTH,PAs,0
BYPLAYERMONTH,AtBats,0
BYPLAYERMONTH,Hits,0
BYPLAYERMONTH,BA,0
BYPLAYERMONTH,OBP,0
BYPLAYERMONTH,SLG,0
BYPLAYERMONTH,OPS,0
BYPLAYERMONTH,_Bases,0
BYPLAYERMONTH,_Reached_Base,0
BYTEAM,Team_Name,1
BYTEAM,Team_SK,1
BYTEAM,PAs,0
BYTEAM,AtBats,0
BYTEAM,Hits,0
BYTEAM,BA,0
BYTEAM,OBP,0
BYTEAM,SLG,0
BYTEAM,OPS,0
BYTEAM,_Bases,0
BYTEAM,_Reached_Base,0
;;;;
run;
/*******************************************************************
Datalines for CHAPTER9LOOKUPTABLES dataset
Generated by %mp_ds2cards()
Licensed under GNU, available on github.com/boemska/macrocore
********************************************************************/
data template.Chapter9lookuptables ;
attrib
hashTable length= $32 label="Member Name"
Column length= $32 label="Column Name"
Is_A_Key length= 8
datasetTag length= $200
;
infile cards dsd delimiter=',';
input
hashTable :$char.
Column :$char.
Is_A_Key
datasetTag :$char.
;
datalines4;
GAMES,Game_SK,1,DW.GAMES
GAMES,Date,0,DW.GAMES
GAMES,Time,0,DW.GAMES
GAMES,Year,0,DW.GAMES
GAMES,Month,0,DW.GAMES
GAMES,DayOfWeek,0,DW.GAMES
GAMES,League,0,DW.GAMES
GAMES,Home_SK,0,DW.GAMES
GAMES,Away_SK,0,DW.GAMES
PLAYERS,Player_ID,1,DW.PLAYERS
PLAYERS,Team_SK,0,DW.PLAYERS
PLAYERS,First_Name,0,DW.PLAYERS
PLAYERS,Last_Name,0,DW.PLAYERS
PLAYERS,Bats,0,DW.PLAYERS
PLAYERS,Throws,0,DW.PLAYERS
PLAYERS,Start_Date,0,DW.PLAYERS
PLAYERS,End_Date,0,DW.PLAYERS
TEAMS,Team_SK,1,DW.TEAMS
TEAMS,Team_Name,0,DW.TEAMS
TEAMS,League_SK,0,DW.TEAMS
;;;;
run;
/*******************************************************************
Datalines for CHAPTER9SPLITS dataset
Generated by %mp_ds2cards()
Licensed under GNU, available on github.com/boemska/macrocore
********************************************************************/
data template.Chapter9splits ;
attrib
hashTable length= $32 label="Member Name"
Column length= $32 label="Column Name"
is_A_Key length= 8
;
infile cards dsd delimiter=',';
input
hashTable :$char.
Column :$char.
is_A_Key
;
datalines4;
BYDAYOFWEEK,DayOfWeek,1
BYDAYOFWEEK,PAs,0
BYDAYOFWEEK,AtBats,0
BYDAYOFWEEK,Hits,0
BYDAYOFWEEK,BA,0
BYDAYOFWEEK,OBP,0
BYDAYOFWEEK,SLG,0
BYDAYOFWEEK,OPS,0
BYDAYOFWEEK,_Bases,0
BYDAYOFWEEK,_Reached_Base,0
BYMONTH,Month,1
BYMONTH,PAs,0
BYMONTH,AtBats,0
BYMONTH,Hits,0
BYMONTH,BA,0
BYMONTH,OBP,0
BYMONTH,SLG,0
BYMONTH,OPS,0
BYMONTH,_Bases,0
BYMONTH,_Reached_Base,0
BYPLAYER,Last_Name,1
BYPLAYER,First_Name,1
BYPLAYER,Player_ID,1
BYPLAYER,PAs,0
BYPLAYER,AtBats,0
BYPLAYER,Hits,0
BYPLAYER,BA,0
BYPLAYER,OBP,0
BYPLAYER,SLG,0
BYPLAYER,OPS,0
BYPLAYER,_Bases,0
BYPLAYER,_Reached_Base,0
BYPLAYERMONTH,Last_Name,1
BYPLAYERMONTH,First_Name,1
BYPLAYERMONTH,Player_ID,1
BYPLAYERMONTH,Month,1
BYPLAYERMONTH,PAs,0
BYPLAYERMONTH,AtBats,0
BYPLAYERMONTH,Hits,0
BYPLAYERMONTH,BA,0
BYPLAYERMONTH,OBP,0
BYPLAYERMONTH,SLG,0
BYPLAYERMONTH,OPS,0
BYPLAYERMONTH,_Bases,0
BYPLAYERMONTH,_Reached_Base,0
BYTEAM,Team_Name,1
BYTEAM,Team_SK,1
BYTEAM,PAs,0
BYTEAM,AtBats,0
BYTEAM,Hits,0
BYTEAM,BA,0
BYTEAM,OBP,0
BYTEAM,SLG,0
BYTEAM,OPS,0
BYTEAM,_Bases,0
BYTEAM,_Reached_Base,0
;;;;
run;
/* "Games.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.GAMES
(
Game_SK char(16) format=$HEX32. label = "Game Surrogate Key"
,Date num format=YYMMDD10. label = "Game Date"
,Time num format=TIMEAMPM8. label = "Game Time"
,Year num label = "Year"
,Month num label = "Month"
,DayOfWeek num Label = "Day of the Week"
,League_SK num label = "League"
,Home_SK num label = "Home Team Surrogate Key"
,Away_SK num label = "Away Team Surrogate Key"
);
quit;
/* "LineUps.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.LINEUPS
(
Game_SK char(16) format=$HEX32. label = "Game Surrogate Key",
Date num format=YYMMDD10. label = "Game Date",
Team_SK num label = "Team Surrogate Key",
Batting_Order num label = "Lineup Position",
Player_ID num format=Z5. label = "Player ID",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Position_Code char(3) informat=$3. label "Position",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R"
);
create index LineUp on template.LINEUPS(Game_SK,Team_SK);
quit;
/* "Pitches.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.PITCHES
(
Game_SK char(16) format=$HEX32. label = "Game Surrogate Key",
Date num format=YYMMDD10. label = "Game Date",
Team_SK num label = "Team Surrogate Key",
Pitcher_ID num label = "Pitcher_ID",
Pitcher_First_Name char(12) label = "Pitcher_First_Name",
Pitcher_Last_Name char(12) label = "Pitcher_Last_Name",
Pitcher_Bats char(1) informat=$1. label = "Bats L, R or Switch",
Pitcher_Throws char(1) informat=$1. label = "Throws L or R",
Pitcher_Type char(3) label "Starter or Reliever",
Inning num label = "Inning",
Top_Bot char(1) label = "Which Half Inning",
Result char(16) label = "Result of the At Bat",
AB_Number num label = "At Bat Number in Game",
Outs num label = "Number of Outs",
Balls num label = "Number of Balls",
Strikes num label = "Number of Strikes",
Pitch_Number num label = "Pitch Number in the AB",
Is_A_Ball num label = "Pitch is a Ball",
Is_A_Strike num label ="Pitch is Strike",
onBase num label ="Number of Men on Base"
);
quit;
/* "Player_Candidates.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.PLAYER_CANDIDATES
(
Player_ID num format=Z5. label = "Player ID",
Team_SK num label = "Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Position_Code char(3) informat=$3. label = "Batter Position",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R"
);
quit;
/* "Player_SCD_All.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.PLAYERS_SCD0
(
Player_ID num format=Z5. label = "Player ID",
Team_SK num label = "Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Position_Code char(3) informat=$3. label "Batter Position",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R"
);
quit;
data TEMPLATE.PLAYERS_SCD1;
set TEMPLATE.PLAYERS_SCD0;
run;
proc sql;
create table TEMPLATE.PLAYERS_SCD2
(
Player_ID num format=Z5. label = "Player ID",
Team_SK num label = "Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Position_Code char(3) informat=$3. label "Batter Position",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R",
Start_Date num format=YYMMDD10. label = "First Game Date",
End_Date num format=YYMMDD10. label = "Last Game Date"
);
create table TEMPLATE.PLAYERS LIKE TEMPLATE.PLAYERS_SCD2(drop=Position_Code);
quit;
proc sql;
create table TEMPLATE.PLAYERS_SCD3
(
Player_ID num format=Z5. label = "Player ID",
Debut_Team_SK num label = "Debut Team Surrogate Key",
Team_SK num label = "Current Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R",
Position_Code char(3) informat=$3. label "Batter Position"
);
quit;
proc sql;
create table TEMPLATE.PLAYERS_SCD3_FACTS
(
Player_ID num format=Z5. label = "Player ID",
Team_SK num label = "Current Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
First num label = "Games at First",
Second num label = "Games at Second",
Short num label = "Games at ShortStop",
Third num label = "Games at Third",
Left num label = "Games in Left",
Center num label = "Games in Center",
Right num label = "Games in Right",
Catcher num label = "Games at Catcher",
Pitcher num label = "Games at Pitcher",
Pinch_Hitter num label = "Games as a Pinch Hitter"
);
create table template.PLAYERS_POSITIONS_PLAYED LIKE TEMPLATE.PLAYERS_SCD3_FACTS;
quit;
proc sql;
create table TEMPLATE.PLAYERS_SCD6
(
Player_ID num format=Z5. label = "Player ID",
Active num label = "Currently Active?",
SubKey num label = "Secondary Key",
Team_SK num label = "Team Surrogate Key",
First_Name char(12) informat=$12. label = "First Name",
Last_Name char(12) informat=$12. label = "Last Name",
Position_Code char(3) informat=$3. label "Batter Position",
Bats char(1) informat=$1. label = "Bats L, R or Switch",
Throws char(1) informat=$1. label = "Throws L or R",
Start_Date num format=YYMMDD10. label = "First Game Date",
End_Date num format=YYMMDD10. label = "Last Game Date"
);
quit;
/* "Runs.sas" from the SAS Press book
Data Management Solutions Using SAS Hash Table Operations:
A Business Intelligence Case Study
*/
proc sql;
create table TEMPLATE.RUNS
(
Game_SK char(16) format=$HEX32. label = "Game Surrogate Key",
Date num format=YYMMDD10. label = "Game Date",
Batter_ID num label = "Batter ID",
Inning num label = "Inning",
Top_Bot char(1) label = "Which Half Inning",
AB_Number num label = "At Bat Number in Game",
Runner_ID num label = "ID of Runner Who Scored"
);
quit;
/*******************************************************************
Datalines for SCHEMA_METADATA dataset
Generated by %mp_ds2cards()
Licensed under GNU, available on github.com/boemska/macrocore
********************************************************************/
data template.SCHEMA_METADATA ;
attrib
hashTable length= $32 label="Member Name"
Column length= $32 label="Column Name"
Is_A_Key length= 8
;
infile cards dsd delimiter=',';
input
hashTable :$char.
Column :$char.
Is_A_Key
;
datalines4;
ATBATS,Game_SK,1
ATBATS,Batter_ID,.
ATBATS,Position_Code,.
ATBATS,Inning,.
ATBATS,Top_Bot,.
ATBATS,AB_Number,.
ATBATS,Result,.
ATBATS,Direction,.
ATBATS,Distance,.
ATBATS,Outs,.
ATBATS,Balls,.
ATBATS,Strikes,.
ATBATS,onFirst,.
ATBATS,onSecond,.
ATBATS,onThird,.
ATBATS,onBase,.
ATBATS,Left_On_Base,.
ATBATS,Runs,.
ATBATS,Is_An_AB,.
ATBATS,Is_An_Out,.
ATBATS,Is_A_Hit,.
ATBATS,Is_An_OnBase,.
ATBATS,Bases,.
ATBATS,Number_of_Pitches,.
CHAPTER10LOOKUPTABLES,hashTable,1
CHAPTER10LOOKUPTABLES,Column,.
CHAPTER10LOOKUPTABLES,Is_A_Key,.
CHAPTER10LOOKUPTABLES,datasetTag,.
CHAPTER10SPLITS,hashTable,1
CHAPTER10SPLITS,Column,.
CHAPTER10SPLITS,is_A_Key,.
CHAPTER9PARMFILE,hashTable,1
CHAPTER9PARMFILE,Column,.
CHAPTER9PARMFILE,is_A_Key,.
GAMES,Game_SK,1
GAMES,Date,.
GAMES,Time,.
GAMES,Year,.
GAMES,Month,.
GAMES,DayOfWeek,.
GAMES,League,.
GAMES,Home_SK,.
GAMES,Away_SK,.
LINEUPS,Game_SK,1
LINEUPS,Team_SK,.
LINEUPS,Batting_Order,.
LINEUPS,Player_ID,.
LINEUPS,Position_Code,.
LINEUPS,Bats,.
LINEUPS,Throws,.
PITCHES,Game_SK,1
PITCHES,Pitcher_ID,.
PITCHES,Pitcher_First_Name,.
PITCHES,Pitcher_Last_Name,.
PITCHES,Pitcher_Type,.
PITCHES,Inning,.
PITCHES,Top_Bot,.
PITCHES,Result,.
PITCHES,AB_Number,.
PITCHES,Outs,.
PITCHES,Balls,.
PITCHES,Strikes,.
PITCHES,Pitch_Number,.
PITCHES,Is_A_Ball,.
PITCHES,Is_A_Strike,.
PITCHES,onBase,.
PLAYERS,Player_ID,1
PLAYERS,Team_SK,.
PLAYERS,First_Name,.
PLAYERS,Last_Name,.
PLAYERS,Bats,.
PLAYERS,Throws,.
PLAYERS,Start_Date,.
PLAYERS,End_Date,.
PLAYERS_POSITIONS_PLAYED,Player_ID,1
PLAYERS_POSITIONS_PLAYED,First,.
PLAYERS_POSITIONS_PLAYED,Second,.
PLAYERS_POSITIONS_PLAYED,Short,.
PLAYERS_POSITIONS_PLAYED,Third,.
PLAYERS_POSITIONS_PLAYED,Left,.
PLAYERS_POSITIONS_PLAYED,Center,.
PLAYERS_POSITIONS_PLAYED,Right,.
PLAYERS_POSITIONS_PLAYED,Catcher,.
PLAYERS_POSITIONS_PLAYED,Pitcher,.
PLAYERS_POSITIONS_PLAYED,Pinch_Hitter,.
RUNS,Game_SK,1