Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study by Paul Dorfman & Don Henderson
Author:Paul Dorfman & Don Henderson [Dorfman, Paul]
Language: eng
Format: epub
Publisher: SAS Institute
Published: 2018-07-08T23:00:00+00:00
7.3.6.1 Performing Table Lookups Using an SCD Type 6 Table
The table lookup into an SCD Type 6 table can be done using the exact same code as shown above for an SCD Type 2 table. However, that does not leverage the potential efficiency benefits of using the Active flag. The following code illustrates first checking to see if the Active row meets the required time/date constraint; and if it does not, the inactive rows are searched.
Program 7.6 Chapter 7 SCD 6.sas (continued)
data tableLookup;
/* Sample Lookup */
retain Player_ID;
if 0 then set bizarro.Players_SCD6(drop=Subkey);
if _n_ = 1 then
do; /* define the hash table */
dcl hash scd(dataset:"bizarro.Players_SCD6",multidata:"Y",ordered:"D"); ❶
scd.defineKey("Player_ID","Active");
scd.defineData("Team_SK","Player_ID","Active","First_Name","Last_Name"
,"Position_Code","Bats","Throws","Start_Date","End_Date");
scd.defineDone();
end; /* define the hash table */
infile datalines;
attrib Date format = yymmdd10. informat = yymmdd10.;
input Player_ID Date; ❷
RC = scd.find(Key:Player_ID,Key:1); ❸
if RC = 0 and (Start_Date le Date le End_Date)
then; ❹
else
do; /* search the inactive rows */
RC = scd.find(Key:Player_ID,Key:0); ❺
do while(RC = 0);
if (Start_Date le Date le End_Date) then leave;
RC = scd.find_next();
end;
end; /* search the inactive rows */
if RC ne 0 then call missing(Team_SK,Active,First_Name,Last_Name ❻
,Position_Code,Bats,Throws,Start_Date,End_Date);
datalines;
10103 2017/10/15
10103 2017/03/23
99999 2017/03/15
10782 2017/03/22
10782 2017/03/21
run;
❶ Define the hash table. Note that adding the Active field as a key can improve lookup performance, especially if the majority of lookups are for the active values.
❷ Read in the sample transactions for our lookups (this is the same data as used for the SCD Type 2 lookup example).
❸ We first use the FIND method to Retrieve the values for the currently active row.
❹ If there is a currently active item (RC = 0), and Date is in range, our search is complete.
❺ Otherwise, search for the inactive items.
❻ If the search fails because either the Player_ID key-value is not found in the hash table or there is no date range match, set the values of the dimensional variables to missing.
The results of the lookup can be seen in the following output.
Output 7.7 Sample SCD Type 6 Lookup Results
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(7382)
Supercharging Productivity with Trello by Brittany Joiner(6641)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6423)
Mastering Tableau 2023 - Fourth Edition by Marleen Meier(6408)
Inkscape by Example by István Szép(6253)
Visualize Complex Processes with Microsoft Visio by David J Parker & Šenaj Lelić(5950)
Build Stunning Real-time VFX with Unreal Engine 5 by Hrishikesh Andurlekar(4947)
Design Made Easy with Inkscape by Christopher Rogers(4624)
Customizing Microsoft Teams by Gopi Kondameda(4160)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3937)
Extending Microsoft Power Apps with Power Apps Component Framework by Danish Naglekar(3750)
Business Intelligence Career Master Plan by Eduardo Chavez & Danny Moncada(3730)
Salesforce Platform Enterprise Architecture - Fourth Edition by Andrew Fawcett(3628)
Pandas Cookbook by Theodore Petrou(3601)
The Tableau Workshop by Sumit Gupta Sylvester Pinto Shweta Sankhe-Savale JC Gillet and Kenneth Michael Cherven(3404)
TCP IP by Todd Lammle(2988)
Drawing Shortcuts: Developing Quick Drawing Skills Using Today's Technology by Leggitt Jim(2923)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2881)
Exploring Microsoft Excel's Hidden Treasures by David Ringstrom(2863)
