Chapter 9 Working with the Loop Transformations
Total Page:16
File Type:pdf, Size:1020Kb
Chapter 9 Working with the Loop Transformations 9.1 Introduction to the Loop Transformations ..................................................................9-3 9.2 Iterating a Job ...............................................................................................................9-7 Demonstration: Exploring the Summary Statistics Transformation ........................................ 9-8 Demonstration: Creating an Iterative Job ............................................................................ 9-16 Exercises .............................................................................................................................. 9-30 9.3 Iterating a Single Transformation (Self-Study) ......................................................... 9-35 Demonstration: Iterating the Create Table Transformation .................................................. 9-39 Demonstration: Using PROC METALIB ............................................................................... 9-53 Demonstration: Enable Parallel Processing ........................................................................ 9-60 Exercises .............................................................................................................................. 9-63 9.4 Solutions to Exercises ............................................................................................... 9-64 9-2 Kompaktkurs: Data Integration Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-3 9.1 Introduction to the Loop Transformations Objectives Explain the purpose of the Loop transformations. Explain the function of the control table. Explain parameter mapping. 3 About Iterative Jobs An iterative job uses the Loop and Loop End transformations to execute one or more processes multiple times. Iterate a Single Transformation Iterate a Job 4 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-4 Kompaktkurs: Data Integration Loop and Loop End Transformations The Loop and Loop End transformations are used to mark the beginning and end, respectively, of an iterative process. They are located in the Control group on the Transformations tab. 5 About Parameters The process that is iterated contains parameters in the form of macro variables. The values for the parameters are provided by the control table. The Loop transformation iterates once for each row in the control table. 6 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-5 The Control Table The control table can be any type of table. The control table can be created in a separate job, or it can be created as part of the iterative job. Example of control table as separate job: Example of control table as part of the “Loop” job: 7 Job and Transformation Parameters Parameters can be defined for transformations and for jobs on the Parameters tab in the Properties window. 8 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-6 Kompaktkurs: Data Integration Parameter Mapping The parameters in the iterated process must be mapped to columns in the control table. This is done on the Parameter Mapping tab in the Loop Properties window. Parameter Mapping tab Parameters in the Columns in the iterated item control table 9 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-7 9.2 Iterating a Job Objectives Review a job that uses the Summary Statistics transformation. Create an iterative job that uses a control table, the Loop transformations, and a parameterized job. 12 Summary Report for United States The country manager for the United States requested a report on customer order information. A job was developed using the Summary Statistics transformation. 13 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-8 Kompaktkurs: Data Integration Exploring the Summary Statistics Transformation In this demonstration, an existing job that uses the Summary Statistics transformation to generate a report for United States customers is executed. The job is reviewed, including the attributes and characteristics of the Summary Statistics transformation. 1. If necessary, access SAS Data Integration Studio using Kari’s credentials. a. Select Start All Programs SAS SAS Data Integration Studio 4.4. b. Verify that the connection profile is Kari’s Work Repository. c. Click OK to close the Connection Profile window and access the Log On window. d. Type Kari as the value for the User ID field and Student1 as the value for the Password field. e. Click OK to close the Log On window. 2. Open the job to review it. a. Click the Folders tab. b. If necessary, expand Data Mart Development Orion Reports Extract and Summary. c. Double-click the DIFT Create Report for US Customer Order Information job. d. Right-click the Extract transformation and select Properties. e. Click the Where tab. Notice the expression that involves the value for US. f. Click Cancel to close the Extract Properties window. Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-9 g. Right-click the Summary Statistics transformation and select Properties. h. Click the Options tab. i. If necessary, click the Assign columns group in the selection pane. j. Verify that Total_Retail_Price and Quantity are to be analyzed across the values of Customer_Gender and Customer_Age_Group. Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-10 Kompaktkurs: Data Integration k. Click the Basic group (under Statistics) in the selection pane. l. Verify that the MIN, MEAN, and MAX statistics are to be calculated for the analysis variables. m. Click the Percentiles group (under Statistics) in the selection pane. n. Verify that the MEDIAN statistic is to be calculated for the analysis variables. Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-11 o. Click the Titles and footnotes group in the selection pane. p. Verify that the formatted value for US (United States) is specified as part of the Heading 2 text. q. Click the ODS options group in the selection pane. r. Verify that the ODS result area has Use HTML as its value. Notice that the filename specified involves a compressed formatted value for US: UnitedStatesCustomerInfo.html. s. Click Cancel to close the Summary Statistics Properties window. Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-12 Kompaktkurs: Data Integration 3. Run the job. a. Return to the DIFT Create Report for US Customer Order Information job. b. Select Actions Run to run the job. c. Verify that all steps completed successfully. d. If necessary, view the log for the executed job. 4. View the HTML document. a. Open Windows Explorer. b. Navigate to S:\Workshop\dift\reports. c. Double-click UnitedStatesCustomerInfo.html to open the generated report. d. If necessary, click to close the security message in the browser window. The generated report is displayed. e. Select File Close to close the report. 5. Return to SAS Data Integration Studio. 6. Select File Close to close the Job Editor. Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-13 Report for Each Country While the report is exactly what the United States country manager requested, other country managers are now requesting the same report but for their respective country. A separate job for each country could be created (all 45 of them!). However, if a change occurred in the requested layout of the report, the management of all these jobs becomes unwieldy. A better solution would be to use an iterative job. 16 Steps for an Iterative Job You can fulfill this request in three steps: Step 1 Create the control table. Step 2 Create the parameterized job. Step 3 Create the iterative job. 17 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 9-14 Kompaktkurs: Data Integration Control Table The control table can be any table that contains rows of data that can be fed into an iteration. The creation of this table can be an independent job or as part of the job flow containing the Loop transformations. In the previous example, that value of country is included in three places: The unformatted value subset data in the Extract transformation. The formatted value is a title for the report in the Summary Statistics transformation. The compressed formatted value builds the name of the HTML file created in the Summary Statistics transformation. 18 Step 1: Create the Control Table This table is populated with the country values. The Extract transformation can be used to get the distinct countries from DIFT Customer Order Information. The code generated by the Extract transformation resembles the following: proc sql; create table difttgt.distinctcountries as select distinct put(customer_country,$country.) as countryname, compress(put(customer_country,$country.)) as ccountryname, put(customer_country,$2.) as countryvalue from difttgt.customerorderinfo; quit; 19 Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Working with the LOOP Transformations 9-15 Step 2: Create the Parameterized Job The three hardcoded values for United