Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Using the SCD Type 1 Loader

Transformation

Load Methods and Loader Transformations


Table Loader SCD SCD
Insert/Update Type 1 Type 2

Retain historical records No No Yes

Update only specified columns No Yes Yes

Only if maintaining
Update without retaining
Yes Yes historical records for
historical records some column changes

Maintain cross-reference table


No Yes Yes
with digest values

Prevent updating a nonmissing


Yes No No
with a missing value

Generate a surrogate key No Yes Yes


94
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.

If the dimension table needs to retain historical records, the SCD Type 2 transformation should be
used. The SCD Type 2 transformation can generate surrogate keys and update columns without
retaining historical records as long as at least one column’s historical records are being maintained.
It can also update selected columns.
The SCD Type 1 transformation can generate surrogate keys, update columns without retaining
historical records, and update selected columns from a table.
The Table Loader transformation cannot retain historical records or update only specific columns, but
it can perform updates without retaining historical records. It can also be configured to prevent
incoming missing values from replacing nonmissing values.
The SCD Type 1 and SCD Type 2 transformations maintain cross reference tables with digest
values. Cross reference tables contain one row for each row in the dimension table. They have a
column for the generated key, the business key, and a digest column. The digest column contains an
encrypted concatenation of the columns selected for change detection and is used to detect
changes between the source and target rows. Cross reference tables make the type of comparisons
performed by the SCD Type 1 and SCD Type 2 transformations more efficient.
Features of SCD Type 1 Transformation
The SCD Type 1 transformation has several primary features:
• A match key is used to match update records with target table records.
• Updates can occur for changes in selected columns.
• A new record can be inserted when no matching key is found.
• A surrogate key can be generated.
• A datetime column can optionally be generated to track the date/time
for each update or insert.

95
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.

The SCD Type 1 Transformation

new records
inserted

new records with key changed records with


columns and a digest key columns; change-
value for all change- tracked columns and
tracked columns a digest value
96
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
SCD Type 1 Example: Target and Source
Key column Change-tracked column

Target table

Source table
(updates)
97
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.

SCD Type 1 Example: Target and Source


Key column Change-tracked column

No change

98
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Change in Change-Tracked Column
Key column Change-tracked column

Salary and
Birth_Date
different but
only Salary will
be updated

99
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.

Missing Value for Change-Tracked Column


Key column Change-tracked column

A missing value
for Salary in
update record
results in a
missing value
replacing a
nonmissing
value in the
target.
100
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Missing Value for Change-Tracked Column
Key column Change-tracked column

No matching
key; new
employee
record will be
added
101
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.

3.06 Poll
Can SCD Type 1 updates be performed by transformations other than
the SCD Type 1 transformation?

 True
 False

102
Copyri g ht © S A S Insti tute Inc. A l l ri g hts reserved.
Using the SCD Type 1 Transformation
This demonstration illustrates updating a dimension table with the SCD Type 1 transformation.
1. If necessary, access SAS Data Integration Studio using Bruno’s credentials.
a. Select Start  All Programs  SAS  SAS Data Integration Studio.
b. Select My Server as the connection profile.
c. Click OK to close the Connection Profile window. The Log On window appears.
d. Enter Bruno in the User ID field and Student1 in the Password field.
e. Click OK to close the Log On window.
2. Import the starter objects.
a. Click the Folders tab.
b. Right-click the Data Mart Development folder and select Import  SAS Package.
The Import SAS Package Wizard appears.
c. Click Browse next to the Enter the location of the input SAS package file field.
The Browse window appears.
1) If necessary, navigate to D:\Workshop\dift\solutions\ELP_Packages.
Note: This package can also be downloaded from the ELP Packages folder on the
Extended Learning Page.
2) Click DI_ELP_SCDType1Demo.spk.
3) Click OK.
d. Click Next until the Summary screen appears (accept the defaults on each panel).
e. Click Next on the Summary screen.
f. Click Finish to complete the import.
3. Create a job that uses the SCD Type 1 transformation to load monthly updates to the Staff
Dimension table.
a. Create the initial job metadata.
1) If necessary, click the Folders tab.
2) If necessary, expand Data Mart Development  Orion SCD.
3) Right-click the Orion SCD folder and select New  Job. The New Job Wizard appears.
4) Enter DIFT SCD1 Update Staff Dimension as the name.
5) Verify that the value for Location is /Data Mart Development/Orion SCD.
6) Click OK. The job editor appears.
b. Add the source table object to the job flow diagram.
1) Click the Folders tab.
2) If necessary, expand Data Mart Development  Orion SCD.
3) Drag the DIFT SCD1 M1 Staff Updates table and drag to the job editor.
c. Add the SCD Type 1 Loader transformation to the job flow diagram.
1) Click the Transformations tab.
2) Expand the Data group.
3) Click SCD Type 1 Loader and drag it to the job editor.
4) Connect the DIFT SCD1 M1 Staff Updates table as input for the SCD Type 1
transformation.
d. Add the output table to the job flow diagram.
1) Click the Folders tab.
2) From the Orion SCD folder, select the DIFT SCD1 Staff Dimension table and drag to
the job editor.
3) Position the mouse pointer on an output item of the SCD Type 1 transformation to see a
description.

4) Connect the fourth output item of the SCD Type 1 transformation to the DIFT SCD1 Staff
Dimension table.

4. Select File  Save to save the current job metadata.


5. Configure the SCD Type 1 transformation.
a. Right-click the SCD Type 1 transformation and select Properties.
b. Click the Keys tab.
c. Double-click Employee_ID in the Available list to move it to the Selected list.
d. Click Generate a surrogate key.
e. Click the ellipsis button next to the Surrogate key column field.
1) Click SK in the DIFT SCD1 Staff Dimension Columns window.
2) Click OK.
Employee_ID selected
as the Key column

Specify to generate a
surrogate key

SK selected as the
surrogate key column

f. Click the Change Columns tab.


1) Double-click Salary in the Available list to move it to the Selected list.
2) Double-click Job_Title in the Available list to move it to the Selected list.

g. Click the Options tab.


1) Verify that the General options group is selected.
2) Under Last update date, select the LastUpdated column.
3) Verify that DATETIME() is specified for Last update expression.

h. Click the Mappings tab.


i. Verify that all columns are mapped except SK and LastUpdated.

Note: The SK and LastUpdated columns are populated by the SCD Type 1 transformation.
j. Click OK to close the SCD Type 1 Properties.
6. Select File  Save to save the current job metadata.
7. Review the current data before running the job.
a. Right-click DIFT SCD1 Staff Dimension and select Open.

b. Right-click DIFT SCD1 M1 Staff Updates and select Open.

Notice the following update transactions:


• Employee 120109: no change in salary or in job_title
• Employee 120110: new salary
• Employee 120111: missing salary
• Employee 120120: new record
c. Click the View Data DIFT SCD1 M1 Staff Updates window and select File  Close.
d. Click the View Data DIFT SCD1 Staff Dimension window and select File  Close.
8. Run the job and view the results.
a. Click Run.
b. Verify that the job completed successfully.
c. Right-click DIFT SCD1 Staff Dimension and select Open.
Notice the following updates:
• Employee 120109: no changes
• Employee 120110: new salary, new LastUpdated value
• Employee 120111: new salary (missing value), new LastUpdated value
• Employee 120120: new record, new SK value, new LastUpdated value
d. Click the View Data DIFT SCD1 Staff Dimension window and select File  Close.
9. Prepare the job for the month 2 updates.
a. In the job editor, right-click DIFT SCD1 M1 Staff Updates and select Replace.
b. In the Table Selector window, click the Folders tab.
c. Expand Data Mart Development  Orion SCD.
d. Select DIFT SCD1 M2 Staff Updates.
e. Click OK.
Note: The Replace action maintains column mappings and transformation configuration
settings where appropriate. These settings would be lost if the Delete action was used.
10. Review the data before running the job.
a. Right-click DIFT SCD1 M2 Staff Updates and select Open.
Notice the following update transactions:
• Employee 120109: no change
• Employee 120110: new job title and new salary
• Employee 120111: new job title and new salary
• Employee 120120: no change
b. Click the View Data DIFT SCD1 M2 Staff Updates window and select File  Close.
11. Run the job and view the results.
a. Click Run.
b. Verify that the job completed successfully.
c. Right-click DIFT SCD1 Staff Dimension and select Open.

Notice the following updates:


• Employee 120109: no change
• Employee 120110: new job title, new salary, new LastUpdated value
• Employee 120111: new job title, new salary, new LastUpdated value
• Employee 120120: no change
d. Click the View Data DIFT SCD1 Staff Dimension window and select File  Close.
12. Select File  Save to save the current job metadata.
13. Select File  Close to close the job.

You might also like