As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 7 SCD 3 w Facts.sas
1 /* "Chapter 7 SCD 3 w Facts.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 _null_;
7  if 0 then set template.Players_SCD3_Facts;
8  if _n_ = 1 then
9  do; /* define the hash table */
10  dcl hash scd(dataset:
11  ifc(exist("bizarro.Players_SCD3_Facts")
12  ,"bizarro.Players_SCD3_Facts"
13  ,"template.Players_SCD3_Facts"
14  )
15  ,ordered:"A");
16  scd.defineKey("Player_ID");
17  scd.defineData("Player_ID","Team_SK"
18  ,"First_Name","Last_Name"
19  ,"First","Second","Short","Third"
20  ,"Left","Center","Right","Catcher"
21  ,"Pitcher","Pinch_Hitter");
22  scd.defineDone();
23  dcl hash uniqueGames();
24  uniqueGames.defineKey("Game_SK"
25  ,"Player_ID"
26  ,"Position_Code");
27  uniqueGames.defineDone();
28  end; /* define the hash table */
29  set bizarro.AtBats(rename = (Batter_ID = Player_ID))
30  end=lr;
31  if scd.find() ne 0 then
32  call missing(First,Second,Short,Third
33  ,Left,Center,Right,Catcher
34  ,Pitcher,Pinch_Hitter);
35  select(Position_Code);
36  when("1B") First + (uniqueGames.add() = 0);
37  when("2B") Second + (uniqueGames.add() = 0);
38  when("SS") Short + (uniqueGames.add() = 0);
39  when("3B") Third + (uniqueGames.add() = 0);
40  when("LF") Left + (uniqueGames.add() = 0);
41  when("CF") Center + (uniqueGames.add() = 0);
42  when("RF") Right + (uniqueGames.add() = 0);
43  when("C" ) Catcher + (uniqueGames.add() = 0);
44  when("SP") Pitcher + (uniqueGames.add() = 0);
45  when("RP") Pitcher + (uniqueGames.add() = 0);
46  when("PH") Pinch_Hitter + (uniqueGames.add() = 0);
47  otherwise;
48  end;
49  scd.replace();
50  if lr;
51  scd.output(dataset:"Bizarro.Players_SCD3_Facts");
52 run;