As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 5 GeneratePositionsDimensionTable.sas
1 /* "Chapter 5 GeneratePositionsDimensionTable.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  infile datalines eof=readall;
8  /* Hash Object as an in memory table */
9  if _n_ = 1 then
10  do; /* define just once */
11  declare hash positions(ordered:"a");
12  positions.defineKey("Position_Grp_SK");
13  positions.defineData("Position_Grp_SK","Position_Code","Position","Count","Starters");
14  positions.defineDone();
15  end; /* define just once */
16  informat Position_Code $3. Position $17. Count Starters 8.;
17  label Position_Grp_SK = "Position Group Surrogate Key"
18  Position_Code = "Position Code"
19  Position = "Position Description"
20  Count = "Number of Players"
21  Starters = "Number of Starters"
22  ;
23  input Position_Code Position & Count Starters;
24  Position_Grp_SK + 1;
25  positions.add(); /* could also use positions.add() or positions.ref() */
26  return;
27  readall:
28  /* output a sorted version of our table */
29  positions.output(dataset:"Bizarro.Positions");
30  return;
31  datalines;
32 SP Starting Pitcher 4 1
33 RP Relief Pitcher 6 0
34 C Catcher 2 1
35 CIF Corner Infielder 3 2
36 MIF Middle Infielder 3 2
37 COF Corner Outfielder 3 2
38 CF Center Fielder 2 1
39 UT Utility 2 0
40 ;
41 data _null_;
42  infile datalines eof=readall;
43  /* Hash Object as an in memory table */
44  if _n_ = 1 then
45  do; /* define just once */
46  declare hash positions(ordered:"a");
47  positions.defineKey("Position_SK");
48  positions.defineData("Position_SK","Position_Grp_FK","Position_Code","Position");
49  positions.defineDone();
50  end; /* define just once */
51  informat Position_Grp_FK 8. Position_Code $3. Position $17.;
52  label Position_SK = "Position Surrogate Key"
53  Position_Grp_FK = "Position Group Surrogate Key"
54  Position_Code = "Position Code"
55  Position = "Position Description"
56 
57  ;
58  input Position_Grp_FK Position_Code Position &;
59  Position_SK + 1;
60  positions.add(); /* could also use positions.add() or positions.ref() */
61  return;
62  readall:
63  /* output a sorted version of our table */
64  positions.output(dataset:"Bizarro.Positions_Snowflake");
65  return;
66  datalines;
67 4 1B First Baseman
68 4 3B Third Baseman
69 5 2B Second Baseman
70 5 SS Shortstop
71 6 LF Left Fielder
72 6 RF Right Fielder
73 ;