Introduction to Proc SQL Katie Minten Ronk, Systems Seminar Consultants, Madison, WI



Similar documents
Introduction to Proc SQL Steven First, Systems Seminar Consultants, Madison, WI

Katie Minten Ronk, Steve First, David Beam Systems Seminar Consultants, Inc., Madison, WI

AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C. Y. Associates

Advanced Subqueries In PROC SQL

Performing Queries Using PROC SQL (1)

Chapter 1 Overview of the SQL Procedure

The Query Builder: The Swiss Army Knife of SAS Enterprise Guide

Paper Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation

Fun with PROC SQL Darryl Putnam, CACI Inc., Stevensville MD

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Handling Missing Values in the SQL Procedure

Foundations & Fundamentals. A PROC SQL Primer. Matt Taylor, Carolina Analytical Consulting, LLC, Charlotte, NC

Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu

Using the SQL Procedure

Oracle SQL. Course Summary. Duration. Objectives

Oracle Database: SQL and PL/SQL Fundamentals

Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database

Effective Use of SQL in SAS Programming

Oracle Database: SQL and PL/SQL Fundamentals

3.GETTING STARTED WITH ORACLE8i

Database Administration with MySQL

Introduction to Microsoft Jet SQL

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Paper An Introduction to SAS PROC SQL Timothy J Harrington, Venturi Partners Consulting, Waukegan, Illinois

Oracle Database: SQL and PL/SQL Fundamentals NEW

Unit 10: Microsoft Access Queries

Quick Start to Data Analysis with SAS Table of Contents. Chapter 1 Introduction 1. Chapter 2 SAS Programming Concepts 7

Welcome to the topic on queries in SAP Business One.

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

9.1 SAS. SQL Query Window. User s Guide

SQL. Short introduction

Five Little Known, But Highly Valuable, PROC SQL Programming Techniques. a presentation by Kirk Paul Lafler

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Access Queries (Office 2003)

Salary. Cumulative Frequency

Labels, Labels, and More Labels Stephanie R. Thompson, Rochester Institute of Technology, Rochester, NY

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Ad Hoc Advanced Table of Contents

DBMS / Business Intelligence, SQL Server

Chapter 2 The Data Table. Chapter Table of Contents

Relational Database: Additional Operations on Relations; SQL

Financial Data Access with SQL, Excel & VBA

Click to create a query in Design View. and click the Query Design button in the Queries group to create a new table in Design View.

Microsoft Access 3: Understanding and Creating Queries

Database Query 1: SQL Basics

SQL Basics. Introduction to Standard Query Language

Inquiry Formulas. student guide

PO-18 Array, Hurray, Array; Consolidate or Expand Your Input Data Stream Using Arrays

Information Systems SQL. Nikolaj Popov

Programming with SQL

Oracle Database 10g: Introduction to SQL

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Lecture 25: Database Notes

Microsoft' Excel & Access Integration

Oracle Database 12c: Introduction to SQL Ed 1.1

Using SQL Queries in Crystal Reports

Oracle Database: SQL and PL/SQL Fundamentals NEW

Using SAS With a SQL Server Database. M. Rita Thissen, Yan Chen Tang, Elizabeth Heath RTI International, RTP, NC

C H A P T E R 1 Introducing Data Relationships, Techniques for Data Manipulation, and Access Methods

Database Applications Microsoft Access

Netezza SQL Class Outline

SQL SELECT Query: Intermediate

EXST SAS Lab Lab #4: Data input and dataset modifications

Report Customization Using PROC REPORT Procedure Shruthi Amruthnath, EPITEC, INC., Southfield, MI

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

A Brief Introduction to MySQL

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

Kaseya 2. Quick Start Guide. for VSA 6.3

Fig. 1 Suitable data for a Crosstab Query.

Introduction to SQL for Data Scientists

Experiences in Using Academic Data for BI Dashboard Development

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

Data Tool Platform SQL Development Tools

Aggregating Data Using Group Functions

Querying Microsoft SQL Server 20461C; 5 days

Relational Databases

Paper TU_09. Proc SQL Tips and Techniques - How to get the most out of your queries

Week 4 & 5: SQL. SQL as a Query Language

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Querying Microsoft SQL Server

Alternatives to Merging SAS Data Sets But Be Careful

Structured Query Language (SQL)

Tips, Tricks, and Techniques from the Experts

Advanced Query for Query Developers

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Subsetting Observations from Large SAS Data Sets

Oracle 10g PL/SQL Training

OLAP Systems and Multidimensional Expressions I

Can SAS Enterprise Guide do all of that, with no programming required? Yes, it can.

PROC SQL for SQL Die-hards Jessica Bennett, Advance America, Spartanburg, SC Barbara Ross, Flexshopper LLC, Boca Raton, FL

Counting the Ways to Count in SAS. Imelda C. Go, South Carolina Department of Education, Columbia, SC

SES Project v 9.0 SES/CAESAR QUERY TOOL. Running and Editing Queries. PS Query

To increase performaces SQL has been extended in order to have some new operations avaiable. They are:

Transcription:

Paper 268-29 Introduction to Proc SQL Katie Minten Ronk, Systems Seminar Consultants, Madison, WI ABSTRACT PROC SQL is a powerful Base SAS Procedure that combines the functionality of DATA and PROC steps into a single step. PROC SQL can sort, summarize, subset, join (merge), and concatenate datasets, create new variables, and print the results or create a new table or view all in one step! PROC SQL can be used to retrieve, update, and report on information from SAS data sets or other database products. This paper will concentrate on SQL s syntax and how to access information from existing SAS data sets. Some of the topics covered in this brief introduction include: Writing SQL code using various styles of the SELECT statement. Dynamically creating new variables on the SELECT statement. Using CASE/WHEN clauses for conditionally processing the data. Joining data from two or more data sets (like a MERGE!). Concatenating query results together. WHY LEARN PROC SQL? PROC SQL can not only retrieve information without having to learn SAS syntax, but it can often do this with fewer and shorter statements than traditional SAS code. Additionally, SQL often uses fewer resources than conventional DATA and PROC steps. Further, the knowledge learned is transferable to other SQL packages. AN EXAMPLE OF PROC SQL SYNTAX Every PROC SQL query must have at least one SELECT statement. The purpose of the SELECT statement is to name the columns that will appear on the report and the order in which they will appear (similar to a VAR statement on PROC PRINT). The FROM clause names the data set from which the information will be extracted from (similar to the SET statement). One advantage of SQL is that new variables can be dynamically created on the SELECT statement, which is a feature we do not normally associate with a SAS Procedure: SELECT STATE, SALES, (SALES *.05) AS TAX (no output shown for this code) THE SELECT STATEMENT SYNTAX The purpose of the SELECT statement is to describe how the report will look. It consists of the SELECT clause and several sub-clauses. The sub-clauses name the input dataset, select rows meeting certain conditions (subsetting), group (or aggregate) the data, and order (or sort) the data: PROC SQL options; SELECT column(s) FROM table-name view-name WHERE expression GROUP BY column(s) HAVING expression ORDER BY column(s); A SIMPLE PROC SQL An asterisk on the SELECT statement will select all columns from the data set. By default a row will wrap when there is too much information to fit across the page. Column headings will be separated from the data with a line and no observation number will appear: 1

SELECT * (see output #1 for results) A COMPLEX PROC SQL The SELECT statement in it s simplest form, needs a SELECT and a FROM clause. The SELECT statement can also have all six possible clauses represented in a query: proc sql; SELECT state, sum(sales) as TOTSALES FROM ussales WHERE state in ( WI, MI, IL ) GROUP BY state HAVING sum(sales) > 40000 ORDER BY state desc; quit; (see output #2 for results) These statements will be reviewed in detail later in the paper. LIMITING INFORMATION ON THE SELECT To specify that only certain variables should appear on the report, the variables are listed and separated on the SELECT statement. The SELECT statement does NOT limit the number of variables read. The NUMBER option will print a column on the report labeled 'ROW' which contains the observation number: PROC SQL NUMBER; SELECT STATE, SALES (see output #3 for results) CREATING NEW VARIABLES Variables can be dynamically created in PROC SQL. Dynamically created variables can be given a variable name, label, or neither. If a dynamically created variable is not given a name or a label, it will appear on the report as a column with no column heading. Any of the DATA step functions can be used in an expression to create a new variable except LAG, DIF, and SOUND. Notice the commas separating the columns: SELECT SUBSTR(STORENO,1,3) LABEL= REGION, SALES, (SALES *.05) AS TAX, (SALES *.05) *.01 (see output #4 for results) THE CALCULATED OPTION ON THE SELECT Starting with Version 6.07, the CALCULATED component refers to a previously calculated variable so recalculation is not necessary. The CALCULATED component must refer to a variable created within the same SELECT statement: SELECT STATE, (SALES *.05) AS TAX, (SALES *.05) *.01 AS REBATE - or - SELECT STATE, (SALES *.05) AS TAX, CALCULATED TAX *.01 AS REBATE 2

(see output #5 for results) USING LABELS AND FORMATS SAS-defined or user-defined formats can be used to improve the appearance of the body of a report. LABELs give the ability to define longer column headings: TITLE REPORT OF THE U.S. SALES ; FOOTNOTE PREPARED BY THE MARKETING DEPT. ; SELECT STATE, SALES FORMAT=DOLLAR10.2 LABEL= AMOUNT OF SALES, (SALES *.05) AS TAX FORMAT=DOLLAR7.2 LABEL= 5% TAX (see output #6 for results) THE CASE EXPRESSION ON THE SELECT The CASE Expression allows conditional processing within PROC SQL: SELECT STATE, CASE WHEN SALES BETWEEN 0 AND 10000 THEN LOW WHEN SALES BETWEEN 10001 AND 15000 THEN AVG WHEN SALES BETWEEN 15001 AND 20000 THEN HIGH ELSE VERY HIGH END AS SALESCAT (see results #7 for results) The END is required when using the CASE. Coding the WHEN in descending order of probability will improve efficiency because SAS will stop checking the CASE conditions as soon as it finds the first true value. Also note that the length of SALESCAT will be the longest value (the length of VERY HIGH or nine characters). No special length statement is required as it is in the data step. Another interesting thing about CASE-WHEN logic is that the same operators that are available on the WHERE statement, are also available in CASE-WHEN logic. These operators are: All operators that IF uses (=, <, >, NOT, NE, AND, OR, IN, etc) BETWEEN AND CONTAINS or? IS NULL or IS MISSING = * LIKE ANOTHER CASE The CASE statement has much of the same functionality as an IF statement. Here is yet another variation on the CASE expression: SELECT STATE, CASE WHEN SALES > 20000 AND STORENO IN ( 33281, 31983 ) THEN CHECKIT ELSE OKAY 3

END AS SALESCAT (see output #8 for results) ADDITIONAL SELECT STATEMENT CLAUSES The GROUP BY clause can be used to summarize or aggregate data. Summary functions (also referred to as aggregate functions) are used on the SELECT statement for each of the analysis variables: SELECT STATE, SUM(SALES) AS TOTSALES GROUP BY STATE; (see output #9 for results) Other summary functions available are the AVG/MEAN, COUNT/FREQ/N, MAX, MIN, NMISS, STD, SUM, and VAR. This capability Is similar to PROC SUMMARY with a CLASS statement. REMERGING Remerging occurs when a summary function is used without a GROUP BY. The result is a grand total shown on every line: SELECT STATE, SUM(SALES) AS TOTSALES (see output #10 for results) REMERGING FOR TOTALS Sometimes remerging is good, as in the case when the SELECT statement does not contain any other variables: SELECT SUM(SALES) AS TOTSALES (see output #11 for results) CALCULATING PERCENTAGE Remerging can also be used to calculate percentages: SELECT STATE, SALES, (SALES/SUM(SALES)) AS PCTSALES FORMAT=PERCENT7.2 (see output #12 for results) Check your output carefully when the remerging note appears in your log to determine if the results are what you expect. SORTING THE DATA IN PROC SQL The ORDER BY clause will return the data in sorted order: Much like PROC SORT, if the data is already in sorted order, PROC SQL will print a message in the LOG stating the sorting utility was not used. When sorting on an existing column, PROC SQL and PROC SORT are nearly comparable in terms of efficiency. SQL may be more efficient when you need to sort on a dynamically created variable: SELECT STATE, SALES 4

ORDER BY STATE, SALES DESC; (see output #13 for results) SORT ON NEW COLUMN On the ORDER BY or GROUP BY clauses, columns can be referred to by their name or by their position on the SELECT cause. The option ASC (ascending) on the ORDER BY clause is the default, it does not need to be specified. SELECT SUBSTR(STORENO,1,3) LABEL= REGION, (SALES *.05) AS TAX ORDER BY 1 ASC, TAX DESC; (see output #14 for results) SUBSETTING USING THE WHERE The WHERE statement will process a subset of data rows before they are processed: SELECT * WHERE STATE IN ( OH, IN, IL ); SELECT * WHERE NSTATE IN (10,20,30); SELECT * WHERE STATE IN ( OH, IN, IL ) AND SALES > 500; (no output shown for this example) INCORRECT WHERE CLAUSE Be careful of the WHERE clause, it cannot reference a computed variable: SELECT STATE, SALES, (SALES *.05) AS TAX WHERE STATE IN ( OH, IN, IL ) AND TAX > 10 ; (see output #15 for results) WHERE ON COMPUTED COLUMN To use computed variables on the WHERE clause they must be recomputed: SELECT STATE, SALES, (SALES *.05) AS TAX WHERE STATE IN ( OH, IL, IN ) AND (SALES *.05) > 10; (see output #16 for results) SELECTION ON GROUP COLUMN The WHERE clause cannot be used with the GROUP BY: 5

SELECT STATE, STORE, SUM(SALES) AS TOTSALES GROUP BY STATE, STORE WHERE TOTSALES > 500; (see output #17 for results) USE HAVING CLAUSE In order to subset data when grouping is in effect, the HAVING clause must be used: SELECT STATE, STORENO, SUM(SALES) AS TOTSALES GROUP BY STATE, STORENO HAVING SUM(SALES) > 500; (see output #18 for results) CREATING NEW TABLES OR VIEWS The CREATE statement provides the ability to create a new data set as output in lieu of a report (which is what happens when a SELECT is present without a CREATE statement). The CREATE statement can either build a TABLE (a traditional SAS dataset, like what is built on a SAS DATA statement) or a VIEW (not covered in this paper): CREATE TABLE TESTA AS SELECT STATE, SALES WHERE STATE IN ( IL, OH ); SELECT * FROM TESTA; (see output #19 for results) The name given on the create statement can either be temporary or permanent. Only one table or view can be created by a CREATE statement. The second SELECT statement (without a CREATE) is used to generate the report. JOINING DATASETS USING PROC SQL A join is used to combine information from multiple files. One advantage of using PROC SQL to join files is that it does not require sorting the datasets prior to joining as is required with a DATA step merge. A Cartesian Join combines all rows from one file with all rows from another file. This type of join is difficult to perform using traditional SAS code. SELECT * FROM GIRLS, BOYS; (see output #20 for results) INNER JOIN A Conventional or Inner Join combines datasets only if an observation is in both datasets. This type of join is similar to a DATA step merge using the IN Data Set Option and IF logic requiring that the observation s key is on both data sets (IF ONA AND ONB). 6

SELECT * FROM GIRLS, BOYS WHERE GIRLS.STATE=BOYS.STATE; (see output #21 for results) JOINING THREE OR MORE TABLES An Associative Join combines information from three or more tables. Performing this operation using traditional SAS code would require several PROC SORTs and several DATA step merges. The same result can be achieved with one PROC SQL: SELECT B.FNAME, B.LNAME, CLAIMS, E.STORENO, STATE FROM BENEFITS B, EMPLOYEE E, FEBSALES F WHERE B.FNAME=E.FNAME AND B.LNAME=E.LNAME AND E.STORENO=F.STORENO AND CLAIMS > 1000; (see output #22 for dataset list and results) CONCATENATING QUERY RESULTS Query results can be concatenated with the UNION operator. The UNION operator keeps only unique observations. To keep all observations, the UNION ALL operator can be used. Traditional SAS syntax would require the creation of multiple tables and then either a SET concatenation or a PROC APPEND. Again, the results can be achieved with one PROC SQL: CREATE TABLE YTDSALES AS SELECT TRANCODE, STORENO, SALES FROM JANSALES UNION SELECT TRANCODE, STORENO, SALES *.99 FROM FEBSALES; (no output shown for this example) IN SUMMARY PROC SQL is a powerful data analysis tool. It can perform many of the same operations as found in traditional SAS code, but can often be more efficient because of its dense language structure. PROC SQL can be an effective tool for joining data, particularly when doing associative, or three-way joins. For more information regarding SQL joins, reference the papers noted in the bibliography. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Katie Minten Ronk Systems Seminar Consultants 2997 Yarmouth Greenway Drive Madison, WI 53713 Phone: (608) 278-9964 Fax: (608) 278-0065 7

Email: kronk@sys-seminar.com Web: www.sys-seminar.com SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product names are trademarks of their respective companies. 8

OUTPUT #1 (PARTIAL): ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ67$7(ÃÃÃÃÃ6$/(6ÃÃ6725(12 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ&200(17 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ6725(1$0 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ6$/(6Ã:(5(Ã6/2:Ã%(&$86(Ã2)Ã&203(7,7256Ã6$/( ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ5216Ã9$/8(Ã5,7(Ã6725( ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ6$/(6Ã6/2:(5Ã7+$1Ã1250$/Ã%(&$86(Ã2)Ã%$'Ã:($7+(5 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ35,&('Ã60$57Ã*52&(56 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ$9(5$*(Ã6$/(6Ã$&7,9,7<Ã5(3257(' ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ9$/8(Ã&,7< OUTPUT #2 (PARTIAL): 67$7(ÃÃ7276$/(6 ddddddddddddddd 0,ÃÃÃÃÃ,/ÃÃÃÃÃ OUTPUT #3 (PARTIAL): 52:ÃÃ67$7(ÃÃÃÃÃ6$/(6 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ OUTPUT #4 (PARTIAL): ÃÃÃÃÃÃ5(*,21ÃÃÃÃÃ6$/(6ÃÃÃÃÃÃÃ7$; ÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃ OUTPUT #5 (PARTIAL): STATE TAX REBATE ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃÃÃ 9

OUTPUT #6 (PARTIAL): ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ5(3257Ã2)Ã7+(Ã86Ã6$/(6 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ$02817Ã2) ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ67$7(ÃÃÃÃÃÃÃ6$/(6ÃÃÃÈÃ7$; ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÇÃÃÇ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÃÇÃÃÇ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃÇÃÃÇ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃÇÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ35(3$5('Ã%<Ã7+(Ã0$5.(7,1*Ã'(37 OUTPUT #7 (PARTIAL): 67$7(ÃÃ6$/(6&$7 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ$9* ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ/2: ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ+,*+ Ã0,ÃÃÃÃÃ9(5<Ã+,*+ OUTPUT #8 (PARTIAL): ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ67$7(ÃÃ6$/(6&$7 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ2.$< ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ2.$< ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ2.$< ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃ&+(&.,7 OUTPUT #9: 67$7(ÃÃ7276$/(6 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃÃÃÃ OUTPUT #10 (PARTIAL): 67$7(ÃÃ7276$/(6 :,ÃÃÃÃÃ :,ÃÃÃÃÃ :,ÃÃÃÃÃ 0,ÃÃÃÃÃ OUTPUT #11: 7276$/(6 10

OUTPUT #12 (PARTIAL): (log message shown) STATE SALES PCTSALES WI 10103.23 5.86% WI 9103.23 5.28% WI 15032.11 8.71% MI 33209.23 19.2% NOTE: The query requires remerging summary Statistics back with the original data. OUTPUT #13 (PARTIAL): STATE SALES --------------- IL 32083.22 IL 22223.12 IL 20338.12 IL 10332.11 MI 33209.23 OUTPUT #14 (PARTIAL): REGION TAX ---------------- 312 516.6055 313 1604.161 313 1111.156 319 1016.906 OUTPUT #15 (THE RESULTING SAS LOG- PARTIAL): ÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃ ÃÃÃÃÃÃÃÃÃ352&Ã64/ ÃÃÃÃÃÃÃÃÃÃÃ6(/(&7Ã67$7(6$/(6Ã6$/(6ÃÃÃ$6Ã7$; ÃÃÃÃÃÃÃÃÃÃÃ)520Ã866$/(6 ÃÃÃÃÃÃÃÃÃÃÃ:+(5(Ã67$7(Ã,1Ã2+,1,/Ã$1'Ã7$;Ã!Ã (5525Ã7+(Ã)2//2:,1*Ã&2/8016Ã:(5(Ã127Ã)281'Ã,1Ã7+( &2175,%87,1*Ã7$%/(6Ã7$; 127(Ã 7KHÃ6$6Ã6\VWHPÃVWRSSHGÃSURFHVVLQJÃWKLVÃVWHSÃEHFDXVH ÃRIÃHUURUV OUTPUT #16 (PARTIAL): 67$7(ÃÃÃÃÃ6$/(6ÃÃÃÃÃÃÃ7$; :,ÃÃÃÃÃÃÃ :,ÃÃÃÃÃÃÃÃ :,ÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃ 11

OUTPUT #17 (THE RESULTING SAS LOG- PARTIAL): ÃÃÃÃ*5283Ã%<Ã67$7(Ã6725( ÃÃÃÃ:+(5(Ã7276$/(6Ã!Ã (5525ÃÃ([SHFWLQJÃRQHÃRIÃWKHÃIROORZLQJÃÃÃÃÃÃ ÄÄÃ ÃÃ Ã!Ã Ã!Ã! Ã(4Ã*(Ã*7Ã/(Ã/7 1(ÃA Ãa ÃÉÃ$1'ÃÄÃ25Ã_ÃÃ+$9,1*Ã25'(5 7KHÃVWDWHPHQWÃLVÃEHLQJÃLJQRUHG (5525ÃÃ7KHÃRSWLRQÃRUÃSDUDPHWHUÃLVÃQRWÃUHFRJQL]HG OUTPUT #18 (PARTIAL): 67$7(ÃÃ6725(12ÃÃ7276$/(6,/ÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃÃÃ 0,ÃÃÃÃÃÃÃÃÃ OUTPUT #19: 67$7(ÃÃÃÃÃ6$/(6,/ÃÃÃÃÃ,/ÃÃÃÃÃ,/ÃÃÃÃÃ,/ÃÃÃÃÃ OUTPUT #20(PARTIAL): 1$0(ÃÃÃÃÃÃÃÃÃ67$7(ÃÃ1$0(ÃÃÃÃÃÃÃÃÃ67$7( dddddddddddddddddddddddddddddddddddddd 1$1&<ÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃ1('ÃÃÃÃÃÃÃÃÃÃÃÃÃ:, 1$1&<ÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃ*(1(ÃÃÃÃÃÃÃÃÃÃÃÃ1< 1$1&<ÃÃÃÃÃÃÃÃÃÃÃ:,ÃÃ$'$0ÃÃÃÃÃÃÃÃÃÃÃÃ&$ -($1ÃÃÃÃÃÃÃÃÃÃÃÃ01ÃÃ1('ÃÃÃÃÃÃÃÃÃÃÃÃÃ:, -($1ÃÃÃÃÃÃÃÃÃÃÃÃ01ÃÃ*(1(ÃÃÃÃÃÃÃÃÃÃÃÃ1< -($1ÃÃÃÃÃÃÃÃÃÃÃÃ01ÃÃ$'$0ÃÃÃÃÃÃÃÃÃÃÃÃ&$ $0(/,$ÃÃÃÃÃÃÃÃÃÃ,/ÃÃ1('ÃÃÃÃÃÃÃÃÃÃÃÃÃ:, $0(/,$ÃÃÃÃÃÃÃÃÃÃ,/ÃÃ*(1(ÃÃÃÃÃÃÃÃÃÃÃÃ1< ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ$0(/,$ÃÃÃÃÃÃÃÃÃÃ,/ÃÃ$'$0ÃÃÃÃÃÃÃÃÃÃÃÃ&$ OUTPUT #21 (PARTIAL): 12

1$0(ÃÃÃÃÃÃ67$7(ÃÃÃÃÃ1$0(ÃÃÃÃÃÃ67$7( ÃÃÃdddddddddddddddddddddddddddddddddddddd ÃÃÃÃÃÃÃÃÃÃÃÃ1$1&<ÃÃÃÃÃ:,ÃÃÃÃÃÃÃÃ1('ÃÃÃÃÃÃÃ:, OUTPUT #22: (03/2<((ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ)(%6$/(6ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ%(1(),76 2%6ÃÃÃÃ)1$0(ÃÃÃÃ/1$0(ÃÃÃÃÃÃ6725(12ÃÃÃÃÃÃÃÃ2%6ÃÃÃÃ67$7(ÃÃÃÃÃÃ6$/(6ÃÃÃÃÃ6725(12ÃÃÃÃÃ2%6ÃÃÃÃ)1$0(ÃÃÃÃ/1$0(ÃÃÃÃÃÃ&/$,06 ÃÃÃÃ$11ÃÃÃÃÃÃ%(&.(5ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ$11ÃÃÃÃÃÃ%(&.(5ÃÃÃÃÃÃÃ ÃÃÃÃ&+5,6ÃÃÃÃ'2%621ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0,ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ&+5,6ÃÃÃÃ'2%621ÃÃÃÃÃÃÃÃ ÃÃÃÃ($5/ÃÃÃÃÃ),6+(5ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ$//(1ÃÃÃÃ3$5.ÃÃÃÃÃÃÃÃ ÃÃÃÃ$//(1ÃÃÃÃ3$5.ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ,/ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ%(77<ÃÃÃÃ-2+1621ÃÃÃÃÃÃ ÃÃÃÃ%(77<ÃÃÃÃ-2+1621ÃÃÃÃÃ ÃÃÃÃ.$5(1ÃÃÃÃ$'$06ÃÃÃÃÃÃÃ )1$0(ÃÃÃÃÃ/1$0(ÃÃÃÃÃÃÃÃÃ&/$,06ÃÃ6725(12Ã67$7( $11ÃÃÃÃÃÃÃ%(&.(5ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ0, $//(1ÃÃÃÃÃ3$5.ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ,/ %(77<ÃÃÃÃÃ-2+1621ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃ,/ 13