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



Similar documents
Release 2.1 of SAS Add-In for Microsoft Office Bringing Microsoft PowerPoint into the Mix ABSTRACT INTRODUCTION Data Access

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

Tutorial 3. Maintaining and Querying a Database

Microsoft Office 2010

DbSchema Tutorial with Introduction in SQL Databases

Switching from PC SAS to SAS Enterprise Guide Zhengxin (Cindy) Yang, inventiv Health Clinical, Princeton, NJ

Step One. Step Two. Step Three USING EXPORTED DATA IN MICROSOFT ACCESS (LAST REVISED: 12/10/2013)

Building Ad Hoc Reports

Business Insight Report Authoring Getting Started Guide

Microsoft Office Access 2007 which I refer to as Access throughout this book

2012 Teklynx Newco SAS, All rights reserved.

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

Query 4. Lesson Objectives 4. Review 5. Smart Query 5. Create a Smart Query 6. Create a Smart Query Definition from an Ad-hoc Query 9

Knowledgebase Article

Using Ad-Hoc Reporting

Introduction to Microsoft Access 2003

INTERMEDIATE Excel 2013

Using an Access Database

2009 Braton Groupe sarl, All rights reserved.

Uni Sales Analysis CRM Extension for Sage Accpac ERP 5.5

CCC Report Center Overview Accessing the CCC Report Center Accessing, Working With, and Running Reports Customizing Reports...

Microsoft Access 2010 handout

Microsoft Access Creating Filters and Tables

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

SQL Server 2005: Report Builder

Paper FF-014. Tips for Moving to SAS Enterprise Guide on Unix Patricia Hettinger, Consultant, Oak Brook, IL

How to Create User-Defined Fields and Tables

Decision Support AITS University Administration. Web Intelligence Rich Client 4.1 User Guide

MicroStrategy Tips and Tricks

There are several ways you can reduce the size of your mailbox, they include:

Instructions for Creating an Outlook Distribution List from an Excel File

BusinessObjects: General Report Writing for Version 5

7. Data Packager: Sharing and Merging Data

BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

You must have at least Editor access to your own mail database to run archiving.

Unit 10: Microsoft Access Queries

Filter by Selection button. Displays records by degree to which they match the selected record. Click to view advanced filtering options

OUTLOOK 2007 USER GUIDE

Decision Support AITS University Administration. EDDIE 4.1 User Guide

Build Your First Web-based Report Using the SAS 9.2 Business Intelligence Clients

Merging Labels, Letters, and Envelopes Word 2013

Intellect Platform - Tables and Templates Basic Document Management System - A101

Business Objects 4.1 Quick User Guide

KeePass Getting Started on Windows

Business Portal for Microsoft Dynamics GP User s Guide Release 5.1

7.0 BW Budget Formulation Report Tips and Tricks

Create a New Database in Access 2010

Visual Studio.NET Database Projects

Using the Drag-and-Drop Report Builder

REUTERS/TIM WIMBORNE SCHOLARONE MANUSCRIPTS COGNOS REPORTS

HOW TO ORGANIZE PICTURES

OUTLOOK 2003: HOW TO GET OUT OF JAIL

TRIAL SOFTWARE GUIDE 1. PURPOSE OF THIS GUIDE 2. DOWNLOAD THE TRIALSOFTWARE 3. START WIDS 4. OPEN A SAMPLE COURSE, PROGRAM

PharmaSUG Paper QT26

Using Word 2007 For Mail Merge

Designing Adhoc Reports

MICROSOFT EXCEL 2010 ANALYZE DATA

The software shall provide the necessary tools to allow a user to create a Dashboard based on the queries created.

Chapter 2 The Data Table. Chapter Table of Contents

Sync Appointments from the Schedule Certifications Screen

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Designing and Running Reports. Applicable to onwards

The LSUHSC N.O. Archive

Before you may use any database in Limnor, you need to create a database connection for it. Select Project menu, select Databases:

Stores copies of items you sent to others, by default. Stores items created offline that you want to send the next time you are online

Mitigation Planning Portal MPP Reporting System

SellerDeck 2013 Reviewer's Guide

HOW TO BURN A CD/DVD IN WINDOWS XP. Data Projects

Mastering Mail Merge. 2 Parts to a Mail Merge. Mail Merge Mailings Ribbon. Mailings Create Envelopes or Labels

Downloading Your Financial Statements to Excel

UDW+ Quick Start Guide to Functionality 2013 Version 1.1

ADP Workforce Now V3.0

Crystal Reports Payroll Exercise

Getting Started Guide

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

Vodafone PC SMS (Software version 4.7.1) User Manual

Stored Documents and the FileCabinet

Microsoft Query, the helper application included with Microsoft Office, allows

Entourage - an Introduction to

IST 195 Lab 11: MS Access

ENTERPRISE DATA WAREHOUSE PRODUCT PERFORMANCE REPORTS USER GUIDE EXTERNAL. Version: 1.0

CowCalf5. for Dummies. Quick Reference. D ate: 3/26 /

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

Data Analysis with Microsoft Excel 2003

Microsoft Access 3: Understanding and Creating Queries

Business Intelligence Getting Started Guide

Sage Abra SQL HRMS Reports. User Guide

Producing Listings and Reports Using SAS and Crystal Reports Krishna (Balakrishna) Dandamudi, PharmaNet - SPS, Kennett Square, PA

MS Excel Template Building and Mapping for Neat 5

Creating and Using Databases with Microsoft Access

Connecting to LUA s webmail

2Creating Reports: Basic Techniques. Chapter

MODULE 2: SMARTLIST, REPORTS AND INQUIRIES

Work with the MiniBase App

General User/Technical Guide for Microsoft Access

MICROSOFT OUTLOOK 2011 ORGANIZE MESSAGES

Batch & Document Management. User Guide

SonicWALL CDP 5.0 Microsoft Exchange InfoStore Backup and Restore

Transcription:

Paper 1557-2014 The Query Builder: The Swiss Army Knife of SAS Enterprise Guide ABSTRACT Jennifer First-Kluge and Steven First, Systems Seminar Consultants, Inc. The SAS Enterprise Guide Query Builder is one of the most powerful components of the software. It enables a user to bring in data, join, drop and add columns, compute new columns, sort, filter data, leverage the advanced expression builder, change column attributes, and more! This presentation provides an overview of the major features of this powerful tool and how to leverage it every day. WHAT IS THE QUERY BUILDER? Enterprise Guide is a user interface for SAS. EG passes SAS code to a server to run the SAS code (whether you are writing code or using the tasks in EG). The server could be your local machine, a server on your network, it could even be on another platform. A task is a point and click user interface in Enterprise Guide that generates SAS code. Each task has an analogous PROC (although not 1 to 1 relationship). One of the most powerful tasks is the Query Builder. The Query Builder allows you to manipulate data tables in a variety of ways, including joining tables, selecting variables, filtering data, sorting data, changing data sources, computing columns, setting up prompts, de-duping observations, adding titles and footnotes, limiting output, changing query options, and more. Quite simply, the query builder will quickly bring together data (joining up to 32 tables per query). It will allow the user to manipulate and modify the data easily. These queries will be quicker and less error prone than coding from scratch. SQL IN THE QUERY BUILDER SQL is a query language used by many software packages. The Query Builder in Enterprise Guide generates PROC SQL code behind the scenes. The user doesn t need to code SQL because the query builder will do the heavy lifting. Example of SQL code in SAS: proc sql options; create table view as /* output table to create */ select column(s) /* Select/create columns */ from table-name view-name /* Name input sources */ where expression /* Sub-set rows from table*/ group by column(s) /* Group rows for summary */ having expression /* Subset GROUP BY results*/ order by column(s) /* Sort resulting rows */ ; quit; An EG user can take the shell SQL code that EG generates and modify with special options, etc. Figure 1: SQL Code From the Query Builder 1

CREATING A NEW QUERY To create a new query in Enterprise Guide (EG), in the Process Flow or Project Window, highlight a data set. On the tasks menu, select Query Builder. You can also do this by right-clicking on the data. The Tables list shows the columns that make up query table. The Select Data tab lists the columns included in the query (the user must add the columns to the Select Data tab to have them show up on the output. These columns can be added to the Select Data tab by double clicking the columns or selecting them and dragging them over to the Select Data tab. The and buttons move columns up/down. The button deletes columns. Figure 2: Selecting Columns in the Query Builder QUERY RESULTS There are three formats for query results/output: data table, data view, or report. A Data Table is a static table of values. It is not updated unless the query is rerun. It can also have tasks run against it. A data view is a dynamic table. It stores logic to carry out on data rather than the data itself. It ss updated as the source data changes. It can also have tasks run against it. A Report is a static HTML document. It is not updated unless the query is rerun. It cannot have tasks run against it. To globally select the query results format, go to the Tools menu, select Options, Query. Select save query result set as, Select Data Table, Data View or Report. After the query runs, objects for the query and its results appear in the Process Flow and Project Tree. The original data set has not changed. Figure 3: Query Results 2

The user can set the output location (a file location, server, or library) of the query, under the options. The default setting is to save the output in a temporary library. This means that the output will have to be recreated each time that Enterprise Guide is closed and reopened. Tasks may be run on query results (if the results are a data table or data view). To run a task on query results, in the Process Flow or Project Tree, highlight the query results. From the Task List, select the Query Builder and proceed as usual. SORTING IN THE QUERY BUILDER Sorting changes the order of the observations in a table by ranking the observations based on the values of one or more variables. This can be done on the Sort Data tab in the Query Builder by dragging columns onto the Sort Data tab. The user can specify an ascending or descending sort. Queries can also be sorted by multiple variables. All of the sort variables should in the Sort Data Tab. Clicking the Up and Down buttons will arrange the variables in order of sort priority. Figure 4: Sorting in the Query Builder FILTERING DATA IN THE QUERY BUILDER Filtering can also be carried out in the Query Builder. A filter specifies a condition that determines which rows will be included in the query results. It does not affect which columns are in the results. For example: Inventory is less than 200, Age is greater than 65, Importance equals urgent. To create a filter, click the Filter Data tab in the Query Builder. Double-click a variable to open the Edit Filter window (or click the filter button). This variable will be the left side of the filter condition. An operator states the relationship between the two sides of the filter condition. Examples of operators are greater than, less than, contains, equal to, and many more. These can all be selected from the Operator drop-down menu. The right side of the filter condition may be a value, a value selected from a list, a group of values, a variable, a user entered value, or a prompt. Advanced filters can contain expressions or functions on either side of the operator. These filters are created using the Advanced Expression Builder. These are built by typing in the expression box, double-clicking variables, values, or functions, or single-clicking operators. Over 500 SAS functions are available in a filter, and can be used with point and click options. 3

Figure 5: Advanced Filters with SAS Functions Multiple filters can be combined. By default, if two or more filters are added to a query, the filters are related by AND. AND means an observation will pass through only if both conditions are true. OR means an observation will pass through if either condition is true or if both are true. To change an AND Filter to an OR Filter, on the Filter Data tab, click Combine Filters to open the Filter Combination window. Click AND between the two filters. Click Change to OR. Figure 6: Changing filters From AND to OR If filters are grouped together, the user must be careful about the group logic. Note the difference between: (Filter 1 AND Filter 2) OR Filter 3 and Filter 1 AND (Filter 2 OR Filter 3). In the Filter Combination window, hold down the CTRL key and click on filters to select filters for grouping. Use the Group and Ungroup buttons to change the way the selected filters are grouped. Filters can also be deleted. On the Filter Data tab, highlight a filter. Click the X button to delete the filter. 4

JOINING DATA TABLES Joining is the process of merging two data sets by fusing together certain observations based on the values of variables. A join can be carried out using the Query Builder. TYPES OF JOINS An automatic join occurs when two data sets in a query have a variable with the same name and type. EG searches for a suitable join variable for an automatic join when the second data table is added to the query. An automatic join is an equijoin by default. In an inner join, a row is included only if the join variable value is common to both tables. Rows without a match are omitted. In a full outer join, all rows from both tables are included. In a right outer join or a left outer join, all rows from one of the tables are included, along with the corresponding rows from the other table. SETTING UP JOINS To add an additional data set to a query, click Add Tables. Click Local Computer, Servers, SAS Folders, or Project. Highlight the name of the data set. Click Open. EG will try to do an automatic join (if it can find variables with the same name and variable type). To view the join, click the Join Tables button. By default, none of the columns from the new table will be included in the query. Double-click columns on the Tables list to add them to the query. A manual join requires the user to specify which variables will be used to join the tables. It is necessary when joining by more than one variable or variables with different names. To perform a manual join, add the second data set. Click OK when a message tells you that you need to join the tables manually. Right-click the join variable from the first table. Select Join <variable> with. Select the name of the second table. Select the name of the join variable from the second table. A window will pop up for you to define what type of join. Click OK to close the Join Properties screen. Click CLOSE to close the Tables and Join screen. Figure 7: A Manual Join in EG If data sets have multiple variables in common, an automatic join uses only one variable to match the data sets. It may be necessary to manually join the tables using other variables the data sets have in common. Right-click the next join variable from the first table. Select Join <variable> with. Select the name of the second table. Select the name of the join variable from the second table. Select the type of join from the pop-up menu. Repeat for additional join variables. Click Close. To remove a join variable, right-click the join symbol connecting the variables. Click Delete Join. 5

Figure 8: Joining By Multiple Variables To join more than two tables, continue adding data sets. Modify joins or make manual joins as necessary. Enterprise Guide can join up to 32 tables in a single query. Figure 9: Output from Joining 3 Tables Right- By default, all joins are inner joins. To change the join type, click the Join Tables button in the Query Builder. click the join symbol ( ). Click Properties. Under Join Type, select the new join type. 6

Figure 10: Changing Join Properties CONCLUSION This paper overviews just some of the capabilities of Enterprise Guide s Query Builder. The Query Builder has much more that it can do. It is intuitive and easy to do so much of what we need in SAS right in this one task. And it s easy! RECOMMENDED READING <HEADING 1> The Missing Semicolon: www.sys-seminar.com Enterprise Guide Tips, Papers, and Webinars Chris Hemedinger-The SAS Dummy http://blogs.sas.com/content/sasdummy/ CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Name: Jennifer First-Kluge and Steven First Organization: Systems Seminar Consultants, Inc. Address: 2997 Yarmouth Greenway DR City, State ZIP: Madison, WI 53711 Work Phone: 608-278-9964 Fax: 608-237-1081 Email: train@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. 7