PROC SQL Phil Vecchione. SQL Structured Query Language Developed by IBM in the early 1970’s From the 70’s to the late 80’s there were different types.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Exploring Microsoft Access 2003 Chapter 3 Information From the Database: Reports and Queries.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.
Exploring Microsoft Access 97 Chapter 3 Information From the Database: Reports and Queries Office graphic copyright by Microsoft Corp.
Exploring Microsoft Access
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
Concepts of Database Management Seventh Edition
Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
Database Management Systems 3ed, Online chapter, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Online Chapter Example is the school of mankind,
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Chapter 6 Example is the school of mankind, and they will learn at no.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
SAS PROCs ISYS 650. PROC Statement Syntax PROC name options; Statements statement options; … RUN;
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Exploring Office Grauer and Barber 1 Information From the Database: Reports and Queries(Wk4)
Concepts of Database Management, Fifth Edition
SAS SQL SAS Seminar Series
Chapter 3 Single-Table Queries
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
SAS SQL Part 2 Alan Elliott. Dealing with Missing Values Title "Dealing with Missing Values in SQL"; PROC SQL; select INC_KEY,GENDER, RACE, INJTYPE, case.
1 Chapter 7 Query-By-Example by Monica Chan CS157B Professor Lee.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
10/31/2012ISC239 Isabelle Bichindaritz1 SQL Graphical Queries Design Query By Example.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
Analyzing Data For Effective Decision Making Chapter 3.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Access Class Outline Data Organization Tables Import and Export of Data Queries Select Calculate Values Aggregation (Count, Sum) Create Append Delete Crosstab.
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 - Information From the Database: Reports.
MICROSOFT ACCESS With your host: Daniel McAllister.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?
Chapter 9 Query-by-Example Pearson Education © 2009.
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
Views Lesson 7.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
WEEK# 12 Haifa Abulaiha November 02,
IS6146 Databases for Management Information Systems Lecture 4: SQL IV – SQL Functions and Procedures Rob Gleasure robgleasure.com.
Be “GUI ready” developing in RPG by Robert Arce from PrismaTech. Be “GUI ready” developing in RPG-ILE Presented by: Robert Arce.
 Review quiz. Answer questions.  Discuss queries: ◦ What is a query? Turning data stored in a database into information for decision making. ◦ You: Completed.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
MIDTERM REVIEW IST 210 Organization of Data IST210 1.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 26 By Tasha Chapman, Oregon Health Authority.
Advanced Accounting Information Systems Day 12 Understanding the SQL Language September 21, 2009.
Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
MICROSOFT ACCESS With your host: Daniel McAllister.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Session 1 Retrieving Data From a Single Table
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
The Database Exercises Fall, 2009.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL – Entire Select.
Chapter 4 Summary Query.
Access: SQL Participation Project
Query Functions.
Chapter 9 Query-by-Example Pearson Education © 2009.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

PROC SQL Phil Vecchione

SQL Structured Query Language Developed by IBM in the early 1970’s From the 70’s to the late 80’s there were different types of SQL, based on different databases. In 1986 the first unified SQL standard (SQL-86) was created. Today the SQL parser that is used by most databases are bases on SQL- 92 standards.

Proc SQL Added to the Base SAS package in version 6 Implemented to allow people familiar with database to use SQL features within SAS A “language within a language”

Anatomy of A PROC SQL Statement proc SQL; select study, patient, age, race, gender from work.demographics where gender=‘M’ group by race; quit;

But The SAS Data Step Already Does That…. Create dataset Update values Delete Records Append new records Create New variables Sort data Merge datasets Create tables Update values Delete Records Insert New Records Create New Variables Sort Data Join tables SAS SQL So what’s so cool about proc SQL?

The Power Of SQL SQL looks at datasets differently from SAS –SAS looks at a dataset one record at a time, using an implied loop that moves from the first record to the last –SQL looks at all the records, as a single object Because of this difference SQL can easily do a few things that are more difficult to do in SAS

Power of SQL: SQL Functions There are a number of built in functions in SQL that can be used in a select statement Because of how SQL handles a dataset, these functions work over the entire dataset Functions: –Count: Counts Values –Sum: Sums Values –Max: Identifies the largest value –Min: Identifies the smallest value –Mean: Averages the values

SQL Functions: Example 12 proc sql; 13 select count(*) as Records 14 from orcl.pat_survey1 15 quit; RECORDS

Power of SQL: Group By Similar to the BY parameter used in SAS Groups the SQL observations by the variable defined When used with the SQL functions allows summary information on groupings rather then the entire dataset

Group By: Example 21 proc sql; 22 select site_n, count(*) as Records 23 from orcl.pat_survey1 24 group by site_n; 25 quit; SITE_N RECORDS

Loading Macro Variables A great feature of Proc SQL is that you can load a value or values from a SQL statement into a macro variable Can put a specific value into a macro variable for use throughout your program Coupled with the SQL functions, you can load calculated values into a macro variable

Loading Macro Variables: Example 43 proc sql; 44 select mean(rhin_age) 45 into: meanage 46 from orcl.pat_survey1 47 where rhin_age is not null; 48quit; 50%put The mean age is: &meanage; AVG The mean age is:

Power of SQL: Merging Between Two Values A merge using a SAS data step requires that the variable described in the BY parameter have an EXACT match SQL joins can contain NON-EXACT parameters for a join Thus, allowing for joins to occur between values

Merging Between Two Values: Example PatientVisit DateConc 14/14/ /10/ /4/ PatientStart DrugEnd Drug 14/13/20034/15/ /19/20034/21/ /22/20033/25/ /9/20034/11/ /1/20033/3/ /9/20035/11/2003 Drug Concentrations Drug Dosing

Merging Between Two Values: Example PatientVisit DateConc 14/14/ /10/ /4/ PatientStart DateEnd Date 14/13/20034/15/ /19/20034/21/ /22/20033/25/ /9/20034/11/ /1/20033/3/ /9/20035/11/2003 Drug Dosing proc sql; select c.patient, c.visit_date, c.conc,d.start_date, d.end_date from drug_conc c, drug_dosing d where c.patient=d.patient ; quit; Drug Concentrations

Merging Between Two Values: Example PatientVisit DateConc 14/14/ /10/ /4/ PatientStart DateEnd Date 14/13/20034/15/ /19/20034/21/ /22/20033/25/ /9/20034/11/ /1/20033/3/ /9/20035/11/2003 Drug ConcentrationsDrug Dosing select c.patient, c.visit_date, c.conc,d.start_date, d.end_date from drug_conc c, drug_dosing d where c.patient=d.patient and (d.start_date le c.visit_date le d.end_date);

References Books –SAS Guide to the SQL Procedure –SQL for Dummies Papers –SQL for People Who Don’t Think They Need SQL: Erin Christen (PharmaSUG 2003)

Thank You Any Questions?