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



Similar documents
Effective Use of SQL in SAS Programming

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

Performing Queries Using PROC SQL (1)

Chapter 1 Overview of the SQL Procedure

Oracle Database 10g: Introduction to SQL

1 Structured Query Language: Again. 2 Joining Tables

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

USING SAS WITH ORACLE PRODUCTS FOR DATABASE MANAGEMENT AND REPORTING

Relational Database Basics Review

CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases

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

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Oracle 10g PL/SQL Training

Using SAS as a Relational Database

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Oracle SQL. Course Summary. Duration. Objectives

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

Financial Data Access with SQL, Excel & VBA

9.1 SAS. SQL Query Window. User s Guide

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

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

Information Systems SQL. Nikolaj Popov

Potential Result Set Differences between Relational DBMSs and the SAS System

SAS PASSTHRU to Microsoft SQL Server using ODBC Nina L. Werner, Madison, WI

Access to Relational Databases Using SAS. Frederick Pratter, Destiny Corp.

SQL Pass-Through and the ODBC Interface

SQL. Short introduction

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Oracle Database 12c: Introduction to SQL Ed 1.1

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

A Brief Introduction to MySQL

SQL SELECT Query: Intermediate

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package Data Federation Administration Tool Guide

Database Query 1: SQL Basics

Relational Databases for the Business Analyst

Paper Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation

and what does it have to do with accounting software? connecting people and business

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

Introduction to SQL for Data Scientists

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

Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables

Maksym Iaroshenko Co-Founder and Senior Software Engineer at Eltrino. Magento non-mysql implementations

ICAB4136B Use structured query language to create database structures and manipulate data

Oracle Database: SQL and PL/SQL Fundamentals

Join Example. Join Example Cart Prod Comprehensive Consulting Solutions, Inc.All rights reserved.

Advanced Subqueries In PROC SQL

Using SAS Enterprise Business Intelligence to Automate a Manual Process: A Case Study Erik S. Larsen, Independent Consultant, Charleston, SC

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

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

# or ## - how to reference SQL server temporary tables? Xiaoqiang Wang, CHERP, Pittsburgh, PA

DBMS / Business Intelligence, SQL Server

In this session, we use the table ZZTELE with approx. 115,000 records for the examples. The primary key is defined on the columns NAME,VORNAME,STR

Structured Query Language (SQL)

Displaying Data from Multiple Tables

Sharding with postgres_fdw

Database Administration with MySQL

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

MOC 20461C: Querying Microsoft SQL Server. Course Overview

IT2305 Database Systems I (Compulsory)

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

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

Oracle Database 10g Express

WRITING EFFICIENT SQL. By Selene Bainum

Oracle Database: SQL and PL/SQL Fundamentals NEW

Databases in Engineering / Lab-1 (MS-Access/SQL)

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

Microsoft Access 3: Understanding and Creating Queries

Advanced Query for Query Developers

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Testing Web Applications for SQL Injection Sam Shober

IT Support Tracking with Request Tracker (RT)

Tech Note 663 HMI Reports: Creating Alarm Database (WWALMDB) Reports

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

Oracle Database: SQL and PL/SQL Fundamentals

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

Automation of Large SAS Processes with and Text Message Notification Seva Kumar, JPMorgan Chase, Seattle, WA

HansaWorld SQL Training Material

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc

SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

SQL Query Performance Tuning: Tips and Best Practices

The prerelease version of SQL was called SEQUEL (for Structured English Query Language), and some people still pronounce SQL as sequel.

Web Development using PHP (WD_PHP) Duration 1.5 months

MySQL for Beginners Ed 3

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Access Queries (Office 2003)

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:


Connect to MySQL or Microsoft SQL Server using R

Introduction to SAS Mike Zdeb ( , #122

Where? Originating Table Employees Departments

FileMaker 12. ODBC and JDBC Guide

CHAPTER 12. SQL Joins. Exam Objectives

2012 Teklynx Newco SAS, All rights reserved.

A basic create statement for a simple student table would look like the following.

Review of SwisSQL Data Migration Tool

1. INTRODUCTION TO RDBMS

Talking to Databases: SQL for Designers

Transcription:

Outline SAS-seminar Proc SQL, the pass-through facility How to make your data processing someone else s problem What is SQL and what is a database Quick introduction to Proc SQL The pass-through facility Examples What is SQL? SQL = Structured Query Language. Developed by IBM in the 1970s for querying, modifying and updating relational databases Adopted and standardized by ANSI and ISO during the 1980s Used with almost) all RDBMS Relational Data Base Management System) e.g. Oracle, DB2, Access, MySQL etc. Most RDBMS also offer enhancements to ANSI SQL What is a database? A database is a collection of logically related data and a description of this data, designed to meet the need for information in an organization. For me, a database is just a collection of tables What is Proc SQL? Proc SQL is a SAS implementation of SQL It can be conceptualized as a combination of the data step, proc summary and proc sort, all at once Using Proc SQL you can execute SQL queries on a remote database server 1

Proc SQL intro - terminology Proc SQL syntax SAS Data step Dataset Variable Observation Merge Append Proc SQL Table Column Row Join Union From the name follows that it is extremely structured It is highly scalable and can be used for a multitude of different tasks anything from simple counts to complicated joins of multiple tables and sub queries It typically cannot do anything that ordinary SAS can t Proc SQL syntax - ing SQL example 1 - ing [distinct] column1, column2, [], from library.table where expression order by column1; = all columns data tablename; keep column1, column2; set library.table; where expression; proc sort; by column1; run; create table women as from cblood.persons where sex = 2 order by birthdate; = all variables SQL example 2 - ing Proc SQL syntax - modifying create table patients as distinct idnr from cblood.transfusion; distinct no duplicate values functioncolumn1) as new1, column2 [+ - /] column3 as new2 from library.table; 2

SQL example 3 - modifying create table dead as deathdate-birthdate)/365.24 as age from cblood.persons where not deathdate is null; Proc SQL syntax - summarizing summary_functioncolumn1) as new1 from library.table group by byvariable having group_conditions; SQL example 4 - summarizing SQL example 5 - summarizing create table cancers as count) as cancers from cblood.cancer group by idnr; The count) function returns the number of rows as defined by the group statement create table unlucky_few as from cblood.cancer group by idnr having count) > 10; Returns 156 unlucky souls with 10 or more cancers Proc SQL syntax joining tables Cartesian products alias1.column1, alias2.column1 from library.table1 as alias1 [inner left right full] join library.table2 as alias2 on join clause Specifies how the two tables are joined Sort of like the by statement in a SAS merge alias1.column1, alias2.column1 from library.table1 as alias1, library.table2 as alias2 Failing to specify a join clause will create a cartesian product. i.e. every row in table1 will be matched to every row in table2 3

SQL example 6 - joining create table unlucky_donors as a.idnr Returns only 4 unlucky donors from cblood.donor as a inner join cblood.cancer as b on a.idnr=b.idnr group by a.idnr having count) > 10; Create view table1 as coalescea.b.idnr) as idnr from cblood.donor as a full outer join cblood.cancer as b on a.idnr=b.idnr group by a.idnr having count) > 10; SQL example controls proc sql outobs=10; create table controls as a.casenr label='', a.exit as indexdate, b.recipient label='', ranuni2) as randomnr from cases a left join available_controls b on a.entry-180 le b.entry le a.entry+180 and a.country=b.country and a.county=b.county and a.bloodgroup=b.bloodgroup and a.age=b.age and b.entry < a.exit < b.exit where a.county ne. and b.county ne. order by a.casenr, calculated randomnr; What is the pass-through facility? The Proc SQL pass-through facility is a SAS tool for directly with a database server/rdbms The Pass-through facility can: - Efficiently run complicated queries - Use native RDBMS functions - Execute RDBMS-specific commands - You can use RDBMS indices When do we pass through? When Proc SQL doesn t get it create table yearly_counts as yeardondate) as year, from cblood.donation group by yeardondate); Not a standard SQL function, so SAS downloads the whole dataset and performs the query locally ~12 minutes So, how do we Pass-through? connect to DBMS-name connection statements); column list from connection to DBMS-name DBMS-query ) disconnect from DBMS-name; DBMS specific query 4

SQL Example 7 - Pass-through connect to oracle user=? path=? password=?); from connection to oracle The Oracle version of the extractyear from dondate) as year, year) function from cblood2.donation group by extractyear from dondate) ~30 seconds ); disconnect from oracle; Pass-through galore! connect to oracle user=? path=? password=?); from connection to oracle a.country, b.sex, truncmonths_betweena.transdate,b.birthdate)/12) as age, from cblood2.transfusion a inner join cblood2.persons b on a.idnr=b.idnr and b.birthdate <= a.transdate where extractyear from a.transdate) between 1968 and 2002 and instrcoalesceb.flag,' '),'ID')=0 group by a.country, b.sex, truncmonths_betweena.transdate,b.birthdate)/12) ); Returns age in exact years Only individuals with a valid ID Considerations for Pass-through The SAS implementation of Proc SQL is anything but standard, so what works with SAS may not work with Oracle Oracle has a very odd way of handling missing values Conclusions Proc SQL in itself is a very powerful tool coupled with a powerful database server, Proc SQL can save you a lot of time 5