Professional Documents
Culture Documents
Using The SCD Type 2 Loader and Lookup Transformations
Using The SCD Type 2 Loader and Lookup Transformations
Transformations
38
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
To support Type 2 slowly changing dimensions, columns are added to a dimension table to
distinguish the current record from historical records such as effective date (or datetime), end date
(or datetime), version number, or current indicator. Other columns are added to provide a primary
key such as a surrogate key or retained key (combined with effective date(time)).
2 Using the SCD Type 2 Loader and Lookup Transformations
39
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Updating a Dimension Table
The SCD Type 2 transformation
1. uses the business key to match incoming records to existing records
in a dimension table
Incoming Customer Records
1
Customer Dimension (SK)
40
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Updating a Dimension Table
The SCD Type 2 transformation
2. detects changes to current records
1
Customer Dimension (SK) 2
41
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Updating a Dimension Table
The SCD Type 2 transformation
3. adds records to the dimension table for changes
Incoming Customer Records
42
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
4 Using the SCD Type 2 Loader and Lookup Transformations
continued...
Updating a Dimension Table: Surrogate Key
The SCD Type 2 transformation
4. generates surrogate key values
Incoming Customer Records
43
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Updating a Dimension Table: Retained Key
The SCD Type 2 transformation
5. generates retained key values and beginning date or datetime values
Incoming Customer Records
44
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 5
5
Customer Dimension (SK)
45
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
46
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
6 Using the SCD Type 2 Loader and Lookup Transformations
continued...
Adding New Records to a Fact Table
The Lookup transformation
1. uses the business key for lookups into the dimension tables
2. uses the current record indicator to determine the current record
Incoming Fact Records
Fact Table
47
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
continued...
Adding New Records to a Fact Table
The Lookup transformation
3. retrieves the primary key values from the dimension tables to be added
as foreign key values to the new fact records.
Incoming Fact Records
Fact Table
48
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The retrieval of the primary key value from the dimension table maintains referential integrity
between the records in the fact table and the records in the dimension table.
Using the SCD Type 2 Loader and Lookup Transformations 7
4
Fact Table
49
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
50
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
8 Using the SCD Type 2 Loader and Lookup Transformations
52
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The SCD Type 2 transformation can perform Type 1 updates on columns that are not involved in
Type 2 updates. At least one column must be configured for Type 2 updates. If only Type 1 updates
are needed, then use the SCD Type 1 transformation.
Business Key
53
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Business Key tab is used to specify one or more columns in a target dimension table that
represent the business key.
Using the SCD Type 2 Loader and Lookup Transformations 9
The business key consists of one or more columns that identify a business entity such as a
customer, a product, or an employee.
Change Detection
54
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Detect Changes tab is used to specify one or more columns in a dimension table that are to be
monitored for changes. The business key is used as the basis for change detection. The business
keys in source rows are compared to the business keys in the target.
Change Tracking
55
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
10 Using the SCD Type 2 Loader and Lookup Transformations
The Change Tracking tab provides three methods for tracking historical records: (1) begin and end
date (or datetime) values (2) version number (3) current record indicator. Multiple methods can be
selected.
Using the SCD Type 2 Loader and Lookup Transformations 11
Generated Key
56
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Generated Key tab is used to specify a column to hold the generated key values, as well as an
expression for generating the key values.
By default, the value of the maximum key code is the largest value in the target column that contains
the generated keys. Non-default values are specified by selecting the Define Max Key button on the
Generated Keys tab. In the resulting window, the Maximum Key Code Generator window, you can
obtain an initial value for NewMaxKey from a specified row, column, and table, or you can run a SAS
program to generate that initial value.
To generate a retained key, you select the Generate Retained Key check box in the Generated Keys
tab. With retained keys, source rows that update existing target rows are written into the target with a
copy of the generated key value from the existing row. With surrogate keys, each row in the target
receives a new generated key value.
The generated key is generated at run time for each new row that is added to the target.
12 Using the SCD Type 2 Loader and Lookup Transformations
57
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
close out
existing entries
58
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 13
59
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
An entry consists of all the rows for a business entity represented by a business key value. If a
source row has the same business key and content as a current row in the target, it might indicate
that the entry is being closed out. The entry is closed out if change tracking is implemented with
begin and end datetime values, and if the end datetime value in the source is younger than the same
value in the target. When this is the case, the new end date is written into the target to close out the
entry.
14 Using the SCD Type 2 Loader and Lookup Transformations
60
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
61
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 15
The Lookup transformation can be used to load a target table with columns taken from a source and
from a number of lookup tables.
When a job containing a Lookup transformation is run, each source row is processed as follows:
• The key columns in the source row are compared to the key columns in the specified lookup
tables.
• If matches are found, specified lookup values and source values are added to the target row in the
transformation’s target table.
16 Using the SCD Type 2 Loader and Lookup Transformations
Lookups Tab
64
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Lookups tab in the Lookup transformation is used to specify lookup properties for each lookup
table.
These lookup properties can consist of the following:
• Source to Lookup columns
• Lookup to Target columns
• WHERE expression
• Exceptions
Using the SCD Type 2 Loader and Lookup Transformations 17
65
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Source to Lookup Mapping tab is used to specify one or more columns to be used to find the
matching record in the lookup (dimension) table for each source record.
The business key column (or columns) in the source table is (are) mapped to the corresponding
column (or columns) in the lookup table.
18 Using the SCD Type 2 Loader and Lookup Transformations
66
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Lookup to Target Mapping tab is used to map the one or more column values that are copied
from the lookup (dimension) table to the target (fact) table when a match is found.
The primary key (surrogate key or combination of retained key with BeginDateTime) in the lookup
table is mapped to the corresponding columns in the target table.
67
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Where tab specifies selection criteria that refine the match between the source row and the
matching rows in the lookup table.
Using the SCD Type 2 Loader and Lookup Transformations 19
68
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
The Exceptions tab is used to specify actions to be taken in response to exception conditions
detected in the lookup table.
Error Tables
The Errors tab is used to specify an error table, an exception table, or both.
69
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
20 Using the SCD Type 2 Loader and Lookup Transformations
Error or exception tables are generated if the appropriate action is selected for the lookup tables.
72
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
a. Customer_ID
b. SKCust
c. BeginDateTimeCust
d. EndDateTimeCust
73
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 21
In this example, the Splitter transformation is not being used to split rows into different tables but
instead routes columns to different tables. The customer, product, and fact columns all come
from the same source and are directed to the correct table using the Splitter transformation.
5. Examine the source for the job.
a. Right-click table object DIFT SCD2 Source Data and select Properties.
b. Click the Columns tab.
24 Using the SCD Type 2 Loader and Lookup Transformations
f. In the main area, verify that Remove duplicate records is set to NODUPKEY.
Note: The first record is the surviving record. Duplicate removal takes place before an SCD
type 2 load because duplicates would lead to many extraneous rows that are closed
out a second after they are recorded.
g. Click Cancel to close the properties window.
8. Investigate the Sort transformation named Sort Dedup ProdDim.
a. Right-click the Sort transformation and select Properties.
b. Click the Sort By Columns tab.
c. Verify Product_ID will be sorted in Ascending sort sequence.
d. Click the Options tab.
e. Verify that SAS Sort is selected in left selection pane.
f. In main area, verify Remove duplicate records is set to NODUPKEY.
g. Click Cancel to close the properties window.
9. Structure the Customer Dimension table for Type 2 slowly changing dimensions.
a. Right-click the DIFT SCD2 Customer Dimension table and select Properties.
b. Click the Columns tab.
c. Click the Customer_ID column to insert new columns after it.
d. Click (New column) four times.
e. Assign the following attributes to the new columns:
c. Use beginning and end dates to track changes for each customer ID, and use a current
record indicator to keep track of the current record for each customer ID.
1) Click the Change Tracking tab.
2) If necessary, click Use beginning and end dates.
3) Select BeginDateTimeCust as the column name for Beginning Date.
4) Select EndDateTimeCust as the column name for the End Date.
The final settings for change tracking should resemble the following:
Using the SCD Type 2 Loader and Lookup Transformations 31
Note: SAS Data Integration Studio provides default expressions for the Change
Tracking columns. The DATETIME function is used to generate the beginning
datetime value. A datetime constant with a future date is used to specify an open-
ended value for the ending datetime. Custom expressions can be specified if
desired.
Note: Use Version Number is available as an alternative method to track the current
record.
32 Using the SCD Type 2 Loader and Lookup Transformations
Note: Default expressions are provided to generate surrogate key values for new and
changed records. To specify a custom expression, click the ellipsis button .
Note: A macro variable, NewMaxKey, is updated automatically with the current maximum
key value. To specify a custom method for obtaining the current maximum key value,
click Define Max Key.
Note: To implement the retained key method, check the Generate retained key option.
Using the SCD Type 2 Loader and Lookup Transformations 33
Note: If no columns are selected on this tab, then all columns will be used to detect
changes, except those used for Change Tracking, Business Key, or Generated Key,
and Type 1 columns.
34 Using the SCD Type 2 Loader and Lookup Transformations
’
l. Click OK to close the SCD Type 2 Properties window.
12. Select File Save to save the job metadata.
13. Configure the SCD Type 2 transformation for the Product dimension.
a. Right-click the SCD Type 2 transformation on the left and select Properties.
b. On the General tab, verify that the name of the transformation has been changed to SCD
Type 2 ProdDim.
c. Use beginning and end dates to track changes for each product ID, and use a current record
indicator to keep track of the current record for each product ID.
1) Click the Change Tracking tab.
2) If necessary, click Use beginning and end dates.
3) Select BeginDateTimeProd as the column name for the beginning date.
4) Select EndDateTimeProd as the column name for the end date.
5) Click Use current indicator.
Using the SCD Type 2 Loader and Lookup Transformations 35
15. Select File Save to save the job metadata to this point.
38 Using the SCD Type 2 Loader and Lookup Transformations
There are six records but only four unique Customer_ID values. Notice in particular the
record for Ines Deisser with a Customer_ID value of 65.
b. Scroll right to see the Product_ID column.
78
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 41
c. Drag the Lookup transformation to the job editor, and drop it below and to the right of the
two dimension tables.
8. Structure the Order Fact table for Type 2 slowly changing dimensions.
a. Right-click the DIFT SCD2 Order Fact table and select Properties.
b. Click the Columns tab.
c. Click the last column to import new columns after it.
d. Click (Import columns). The Import Columns window appears.
1) On the Folders tab, expand Data Mart Development Orion SCD DIFT SCD2
Customer Dimension.
2) Double-click SKCust to move it to the selected list.
3) Expand DIFT SCD2 Product Dimension.
4) Double-click SKProd to move it to the selected list.
Using the SCD Type 2 Loader and Lookup Transformations 45
3) In the Lookup Properties - DIFT SCD2 Customer Dimension window, click the Source to
Lookup Mapping tab.
a) Click the Customer_ID column in the Source table pane.
b) Click the Customer_ID column in the Lookup table pane.
c) Click to map the selected columns.
The Source to Lookup Mapping tab should resemble the following:
The Source to Lookup Mapping specifies the key for the lookup. This should be the
business key.
Using the SCD Type 2 Loader and Lookup Transformations 49
The Lookup to Target Mapping specifies the value to be retrieved. This should be the
primary key.
50 Using the SCD Type 2 Loader and Lookup Transformations
The Where filters the records that are returned from the lookup. We want the current
record for the business key.
6) Click the Exceptions tab.
7) Accept the default combinations of conditions and actions.
Using the SCD Type 2 Loader and Lookup Transformations 51
Note: Five default exceptions are defined. Two actions both associated with Lookup
Value Not Found can populate an error and an exception table.
8) Click OK to close the Lookup Properties - DIFT SCD2 Customer Dimension window. A
warning appears.
3) In the Lookup Properties - DIFT SCD2 Product Dimension window, click the Source to
Lookup Mapping tab.
a) Click the Product_ID column in the Source table pane.
b) Click the Product_ID column in the Lookup table pane.
c) Click to map the selected columns.
The Source to Lookup Mapping tab should resemble the following:
52 Using the SCD Type 2 Loader and Lookup Transformations
The Lookup transformation uses the Product_ID value in the incoming transactions
to do a lookup into the Product Dimension table to find a matching Product_ID
value.
4) Click the Lookup to Target Mapping tab.
a) Click SKProd column in the Lookup table pane.
b) Click SKProd column in the Target table pane.
c) Click to map the selected columns.
The Lookup to Target Mapping tab should resemble the following:
Using the SCD Type 2 Loader and Lookup Transformations 53
The lookup transformation retrieves the SKProd value from the DIFT SCD2 Product
Dimension table and assigns it to the SKProd column in the target table. This links
the transaction in the target table to the current record for the Product ID in the
Product Dimension table.
5) Click the Where tab.
a) On the Data Sources tab, expand the SCD2ProdDim table.
b) Click the CurrRecProd column.
c) Click Add to Expression to insert the column reference in the Expression Text pane.
d) Type = 1 to complete the expression.
The Where tab should resemble the following:
Recall that the two lookup tables (DIFT SCD2 Customer Dimension and DIFT SCD2
Product Dimension) each had properties set with actions of Add Row To Error Table
and Add Row To Exception Table where each action was associated with the
condition Lookup Value Not Found. These actions require the above configuration on
the Errors tab.
Two additional result sets will now appear for the Lookup transformation, one for the
error table and one for the exception table. These tables can be registered to a
permanent location if desired.
Exception Table
Error Table
56 Using the SCD Type 2 Loader and Lookup Transformations
These mappings for the Lookup transformation were established in an earlier step.
g. Click OK to close the Lookup Properties window.
11. Select File Save to save the job metadata.
12. Configure the Table Loader transformation.
a. Right-click the Table Loader transformation and select Properties.
b. Click the Load Technique tab.
c. Select Append to Existing as the load style.
15. Select File Save to save the job metadata to this point.
58 Using the SCD Type 2 Loader and Lookup Transformations
16. Verify the order of processing on the Diagram tab in the job editor window.
Recall that the number in the upper left corner of the transformation indicates the order
of processing.
Using the SCD Type 2 Loader and Lookup Transformations 59
There are six records but only four unique Customer_ID values. Notice in particular the
record for Ines Deisser with a Customer_ID value of 65.
b. Scroll right to see the Product_ID column.
e. Verify that the six unique records from the source were loaded.
b. Verify that the Lookup and Table Loader transformations completed successfully.
a. Right-click the DIFT SCD2 Order Fact table and select Open.
b. Scroll right to see the following columns:
The SKCust column has duplicate values for the duplicate values of Customer_ID.
c. Select File Close to close the View Data window.
21. Update the job for month 2 (change the source table).
a. Right-click the DIFT SCD2 Source Data object and select Properties.
1) Click the Physical Storage tab.
2) Change the physical name to SCD2SourceDataM02.
b. Click OK to close the DIFT SCD2 Source Data Properties window.
22. View the source data for month 2.
a. Right-click DIFT SCD2 Source Data and select Open.
The data is displayed in the View Data window.
There are five records for month 2. Notice that the name of Ines Deisser (Customer_ID=65)
has changed to Ines Muller.
b. Select File Close to close the View Data window.
23. Run the job with the new source table.
a. Select Actions Run.
b. Verify that all steps are completed successfully.
62 Using the SCD Type 2 Loader and Lookup Transformations
Recall that one of the fields being monitored for changes was the Customer_Name field. For
the records where Customer_ID=65, the name changed, so the original record was marked
inactive (CurrRecCust=0) and the end date was updated on the inactive record. The “new”
record for Customer_ID=65 was given a new surrogate key (SKCust=7) and was marked as
active (CurrRecCust=1).
b. Select File Close to close the View Data window.
Using the SCD Type 2 Loader and Lookup Transformations 63
c. Right-click the DIFT SCD2 Product Dimension table and select Open.
The five new source records represent new Product_ID values, so they were all added to
the product dimension.
d. Select File Close to close the View Data window.
e. Right-click the DIFT SCD2 Order Fact table and select Open.
All source records from month 1 and month 2 are loaded into the fact table. Notice that both
records for Customer_ID =65 have the correct values for SKCust.
f. Select File Close to close the View Data window.
25. Update the job for month 3 (change the source table).
a. Right-click the DIFT SCD2 Source Data object and select Properties.
1) Click the Physical Storage tab.
2) Change the physical name to SCD2SourceDataM03.
b. Click OK to close the DIFT SCD2 Source Data Properties window.
64 Using the SCD Type 2 Loader and Lookup Transformations
There are 10 records for month 3. Notice that Ines’s (Customer_ID=65) last name changed
back to Deisser.
b. Select File Close to close the View Data window.
27. Run the job with the new source table.
a. Select Actions Run.
b. Verify that all steps are
completed successfully.
Once again, for Customer_ID=65, the Customer_Name changed back to the original name
of Ines Deisser. Thus, the last current record was marked inactive (CurrRecCust=0) and the
end date was updated on the inactive record. The “new” record for Customer_ID=65 was
given a new surrogate key (SKCust=10) and was marked as active (CurrRecCust=1).
In addition, Customer_ID=142 had a name change (Albert to Burt), so the new record is
marked as active, the old record was closed out, and a new surrogate key was generated.
b. Select File Close to close the View Data window.
66 Using the SCD Type 2 Loader and Lookup Transformations
c. Right-click the DIFT SCD2 Product Dimension table and select Open.
Verify that there are 21 records and that all records are “current” (that is, all records have
CurrRecProd=1).
d. Select File Close to close the View Data window.
Using the SCD Type 2 Loader and Lookup Transformations 67
e. Right-click the DIFT SCD2 Order Fact table and select Open.
All source records for the three months are loaded into the fact table.
Notice that all records for Customer_ID =65 have the correct values for SKCust.
Similarly, notice that both records for Customer_ID=142 have the correct values for SKCust.
f. Select File Close to close the View Data window.
29. Select File Save to save the diagram and job metadata to this point.
30. Select File Close to close the job editor window.
68 Using the SCD Type 2 Loader and Lookup Transformations
Exercises (Optional)
This exercise accesses metadata that are similarly defined to that used in the previous demo.
Properties of the table objects are investigated, properties of the SCD Type 2 and Lookup
transformations are updated, and the job is run using three different source tables.
Use Bruno’s credentials to complete this exercise.
1. Importing Starter Objects
• Access SAS Data Integration Studio using the My Server connection profile using Bruno's
credentials (Bruno/Student1).
• From the Data Mart Development folder, import starter objects from
DI_ELP_SCDType2Exercise.spk (SAS package located in
D:\Workshop\dift\solutions\ELP_Packages).
Note: This package can also be downloaded from the ELP Packages folder on the
Extended Learning Page.
– Choose All Objects.
– If necessary, create the needed physical folder.
Question: How many library objects were imported into the Orion SCD folder?
Answer: _________________________________________________________
Question: What is the name of the physical folder needed for a successful import?
Answer: _________________________________________________________
2. Implementing Type 2 Slowly Changing Dimensions with the Retained Key Method
• If necessary, prepare for the exercise by deleting the physical tables from the
D:\Workshop\dift\scdtarget folder.
• The DIFT SCDR2K Populate Star Schema job is like the job created with surrogate key
columns in the demonstration. Verify that the tables are set up correctly for SCD:
– Verify that the DIFT SCD2RK Customer Dimension table has RKCust,
BeginDateTimeCust, EndDateTimeCust, and CurrRecCust columns following the
Customer_ID column.
– Verify that the DIFT SCD2RK Product Dimension table has RKProd,
BeginDateTimeProd, EndDateTimeProd, and CurrRecProd columns following the
Product_ID column.
• Update the configuration of the SCD Type 2 transformations.
– Edit the properties of the SCD Type 2 CustDim transformation.
– On the Generated Key tab, select the RKCust column. Set the Generate retained key
option.
– Edit the properties of the SCD Type 2 ProdDim transformation.
– On the Generated Key tab, select the RKProd column. Set the Generate retained key
option.
• Update the configuration of the Lookup transformation.
– On the Mappings tab, verify that 12 columns are mapped. The remaining four columns will
be populated by the transformation.
Using the SCD Type 2 Loader and Lookup Transformations 69
– In the Lookup Properties for the Customer Dimension table, update the Lookup to Target
Mapping to map RKCust and BeginDatetimeCust to the same named columns in the
target.
– Verify that the WHERE expression selects the current record and the Source to Lookup
Mapping tab maps the business key in the dimension table to the lookup table.
– In the Lookup Properties for the Product Dimension table, update the Lookup to Target
Mapping to map RKProd and BeginDatetimeProd to the same named columns in the
target.
– Verify that the WHERE expression selects the current record and the Source to Lookup
Mapping tab maps the business key in the dimension table to the lookup table.
• Run the job for the three months of data provided.
– Verify that the DIFT SCD2 Source Data physical storage references the
SCD2SourceDataM01 table.
– Run the job for month 1.
– Verify that the job completes successfully, view the resultant tables, and verify that the
results make sense.
– Update the DIFT SCD2 Source Data physical storage to reference the
SCD2SourceDataM02 table.
• Run the job for month 2.
• Verify that the job completes successfully, view the resultant tables, and verify that the results
make sense.
• Update the DIFT SCD2 Source Data physical storage to reference the SCD2SourceDataM03
table.
• Run the job for month 3.
• Verify that the job completes successfully, view the resultant tables, and verify that the results
make sense.
• Save and close the job.
70 Using the SCD Type 2 Loader and Lookup Transformations
Using the SCD Type 2 Loader and Lookup Transformations 71
Solutions
Solutions to Exercises
1. Implementing Type 2 Slowly Changing Dimensions with the Retained Key Method
a. If necessary, access SAS Data Integration Studio using Bruno’s credentials.
1) Select Start All Programs SAS SAS Data Integration Studio.
2) Select My Server as the connection profile.
3) Click OK to close the Connection Profile window. The Log On window appears.
1) Enter Bruno in the User ID field and Student1 in the Password field.
2) Click OK to close the Log On window.
Import a copy of the job created in the SCD Type 2 demonstration modified such that the
dimension tables can be set up with a retained key rather than a surrogate key.
b. Import starter objects.
1) Click the Folders tab.
2) Right-click the Data Mart Development folder and select Import SAS Package.
3) Select the Browse button.
4) Navigate to D:\Workshop\dift\solutions\ELP_Packages.
5) Select the DI_ELP_SCDType2Exercise.spk package and press OK.
6) Accept the default selections for the rest of the pages in the wizard by clicking Next.
7) Click Finish.
c. Verify that the imported tables are correctly configured for SCD.
1) Right-click the DIFT SCD2RK Customer Dimension table and select Properties.
2) Click the Columns tab.
72 Using the SCD Type 2 Loader and Lookup Transformations
6) Click Cancel to close the DIFT SCD2RK Customer Dimension Properties window.
7) Right-click the DIFT SCD2RK Product Dimension table and select Properties.
8) Click the Columns tab.
Using the SCD Type 2 Loader and Lookup Transformations 73
12) Click Cancel to close the DIFT SCD2RK Product Dimension Properties window.
74 Using the SCD Type 2 Loader and Lookup Transformations
c) Click to map RKCust and BeginDateTimeCust from the lookup table to the target
table.
c) Click to map RKCust and BeginDateTimeCust from the lookup table to the target
table.
f) Click OK to close the Lookup Properties - DIFT SCD2RK Product Dimension window.
9) Click the Errors tab.
10) Verify that both the Error and Exception tables are configured.
11) Click OK to close the Lookup Properties window.
h. Verify that the source data are for month 1.
1) In the diagram, right-click the DIFT SCD2 Source Data table and select Properties.
2) Click the Physical Storage tab.
3) Verify that the physical name is SCD2SourceDataM01.
4) Click OK to close the DIFT SCD2 Source Data Properties window.
i. Select File Save to save the job metadata.
j. Run the job for the first month.
1) Click Run.
2) Verify that the job completed successfully.
k. View the results.
1) Right-click the DIFT SCD2RK Customer Dimension table and select Open. The data is
displayed in the View Data window.
78 Using the SCD Type 2 Loader and Lookup Transformations
There are five records for month 2. Notice that the name of Ines Deisser (Customer_ID
=65) has changed to Ines Muller, and the name field is a field being tracked for changes.
3) Select File Close to close the View Data window.
m. Select File Save to save the job metadata.
n. Run the job for the first month.
1) Click Run.
2) Verify that the job completed successfully.
o. View the results.
1) Right-click the DIFT SCD2RK Customer Dimension table and select Open.
The name change resulted in a new record for Customer_ID =65. The new record has
retained the value of the generated key, RKCust. The end datetime and current record
indicator values in the previous record were updated.
2) Select File Close to close the View Data window.
3) Right-click the DIFT SCD2RK Product Dimension table and select Open.
80 Using the SCD Type 2 Loader and Lookup Transformations
All five source records represent new Product_ID values, so they were all added to
the product dimension with new generated key values.
4) Select File Close to close the View Data window.
5) Right-click the DIFT SCD2RK Order Fact table and select Open.
All source records from month 1 and month 2 are loaded into the Fact table. Notice
that both records for Customer_ID=65 have the correct value for RKCust and the
correct values for BeginDateTimeCust. Because RKCust is not unique in either the
Fact table or the Dimension table, the combination of RKCust and
BeginDateTimeCust must be used as the key to relate a record in the Fact table to
the corresponding record in the Dimension table.
6) Select File Close to close the View Data window.
p. Review the data and run the job for the third month.
1) From the job diagram, right-click the DIFT SCD2 Source Data table and select
Properties.
2) Click the Physical Storage tab.
3) Update the physical name to SCD2SourceDataM03.
4) Click OK to close the DIFT SCD2 Source Data Properties window.
Using the SCD Type 2 Loader and Lookup Transformations 81
5) Right-click the DIFT SCD2 Source Data table and select Open.
There are 10 records for month 3. Notice that Ines’ (Customer_ID=65) last name
changed back to Deisser. In addition, Customer_ID=142 has a changed first name.
6) Select File Close to close the View Data window.
q. Select File Save to save the job metadata.
r. Run the job for the first month.
1) Click Run.
2) Verify that the job completed successfully.
s. View the results.
1) Right-click the DIFT SCD2RK Customer Dimension table and select Open.
Again, the name change resulted in a new (third) record for Customer_ID=65 with a
retained generated key value (RKCust). The end datetime and current record indicator in
the previous old record were updated.
Customer_ID=142 also had a name change, which resulted in a new record.
2) Select File Close to close the View Data window.
82 Using the SCD Type 2 Loader and Lookup Transformations
3) Right-click the DIFT SCD2RK Product Dimension table and select Open.
4) Verify that no changed data occurred for this dimension.
5) Select File Close to close the View Data window.
6) Right-click the DIFT SCD2RK Order Fact table and select Open.
All 21 source records from months 1, 2, and 3 are loaded into the Fact table. Notice that
all records for Customer_ID=65 have the correct value for RKCust as well as that for
BeginDateTimeCust. The combination of RKCust and BeginDateTimeCust represents
the (foreign) key in the Fact table that links to the corresponding (primary) key in the
dimension table.
7) Select File Close to close the View Data window.
8) Select File Close to close the job.
Using the SCD Type 2 Loader and Lookup Transformations 83
34
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
51
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
84 Using the SCD Type 2 Loader and Lookup Transformations
a. Customer_ID
b. SKCust
c. BeginDateTimeCust
d. EndDateTimeCust
The SKCust column is the primary key for the Customer Dimension table and
is copied to the Order Fact table on the Lookup to Target Mapping tab of the
Lookup transformation.
74
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 2 Loader and Lookup Transformations 85
79
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
True
False
The SCD Type 2 transformation can perform SCD Type 1 updates if at least one
column has been selected for SCD Type 2 updates.
103
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.