12 %let from = %sysfunc(inputn(&from,date9.));
13 %let to = %eval(&from + &nweeks*7 - 1);
15 %
do date = &from %to &to;
22 set template.LineUps bizarro.Positions_Snowflake;
28 declare hash positions(dataset:
"bizarro.Positions");
29 positions.defineKey(
"Position_Grp_SK");
30 positions.defineData(
"Position_Grp_SK",
"Position_Code",
"Count",
"Starters");
31 positions.defineDone();
32 declare hiter positionIter(
"positions");
34 declare hash positions_snowflake(dataset:
"bizarro.Positions_Snowflake",ordered:
"A",multidata:
"Y");
35 positions_snowflake.defineKey(
"Position_Grp_FK");
36 positions_snowflake.defineData(
"Position_Grp_FK",
"Position_Code");
37 positions_snowflake.defineDone();
39 declare hash LineUp(multidata:
"Y");
40 rc = LineUp.defineKey(
"Game_SK",
"Team_SK");
41 rc = LineUp.defineData(
"Game_SK",
"Team_SK",
"Date",
"Batting_Order",
"Player_ID",
"First_Name",
"Last_Name",
"Position_Code",
"Bats",
"Throws");
42 rc = LineUp.defineDone();
44 declare hash players(dataset:
"bizarro.Player_Candidates(where=(Team_SK))",ordered:
"A",multidata:
"Y");
45 rc = players.defineKey(
"Team_SK",
"Position_Code");
46 rc = players.defineData(
"Team_SK",
"Player_ID",
"First_Name",
"Last_Name",
"Bats",
"Throws");
47 rc = players.defineDone();
50 set bizarro.trades end = lr;
51 where trade_date le &date;
52 do while(players.do_over(Key:_team_sk,Key:_Position_Code) = 0);
53 if player_id = traded_id then
57 Position_Code = _Position_Code;
64 declare hash games(dataset:
"bizarro.Games(where=(date=&date))",multidata:
"Y");
65 rc = games.defineKey(
"Date");
66 rc = games.defineData(
"Game_SK",
"Away_SK",
"Home_SK");
67 rc = games.defineDone();
69 games_rc = games.find(Key:&date);
70 do while (games_rc = 0);
71 do team_sk = away_sk, home_sk;
72 rc = positionIter.first();
73 P_Grp = Position_Code;
74 grp_rc = positions_snowflake.find(Key:Position_Grp_SK);
76 prc = players.find(Key:Team_SK,Key:P_grp);
78 Batting_Order = uniform(&seed5*&date);
79 if divide(Starters,Count) gt Batting_Order then
81 if position_code =
"SP" then Batting_Order = 9;
83 if grp_rc = 0 then grp_rc = positions_snowflake.find_next(Key:Position_Grp_SK);
86 else if position_code ne
"SP" then
88 _position_code = position_code;
89 if position_code =
'RP' then Batting_Order = 1e6;
96 position_code = _position_code;
99 prc = players.find_next(Key:Team_SK,Key:P_grp);
101 *
if Position_Code =
'UT' then
103 * Batting_Order = 9 + uniform(&seed5*&date);
104 *Position_Code =
'PH';
107 rc=positionIter.next();
108 P_Grp = Position_Code;
109 grp_rc = positions_snowflake.find(Key:Position_Grp_SK);
112 games_rc = games.find_next();
114 LineUp.output(dataset:
"Lineups");
118 proc sort data = lineups out = lineups;
119 by game_sk team_sk batting_order;
122 %
if %sysfunc(exist(bizarro.LineUps)) %then
125 delete from bizarro.Lineups
126 where Game_SK in (select distinct Game_SK from Lineups);
131 data bizarro.LineUps;
136 data bizarro.LineUps(index=(LineUp=(Game_SK Team_SK)));
141 if first.team_sk then Order=0;
143 if batting_order ne int(batting_order) and
new then batting_order = min(Order,9);
146 %mend generateLineUps;