SAS SQL #1. SAS Structured Query Language, An Introduction. JC Wang

Similar documents
Performing Queries Using PROC SQL (1)

Oracle SQL. Course Summary. Duration. Objectives

Chapter 1 Overview of the SQL Procedure

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals

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

Handling Missing Values in the SQL Procedure

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

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

3.GETTING STARTED WITH ORACLE8i

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

Oracle Database 12c: Introduction to SQL Ed 1.1

Microsoft Access 3: Understanding and Creating Queries

Financial Data Access with SQL, Excel & VBA

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

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

Programming with SQL

Oracle 10g PL/SQL Training

Welcome to the topic on queries in SAP Business One.

Database Applications Microsoft Access

Advanced Query for Query Developers

SQL Basics. Introduction to Standard Query Language

SQL SELECT Query: Intermediate

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

Ad Hoc Advanced Table of Contents

Introduction to Microsoft Jet SQL

Oracle Database: SQL and PL/SQL Fundamentals NEW

9.1 SAS. SQL Query Window. User s Guide

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

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Using SQL Queries in Crystal Reports

Query. Training and Participation Guide Financials 9.2

Access Queries (Office 2003)

Relational Database: Additional Operations on Relations; SQL

Salary. Cumulative Frequency

PeopleSoft Query Training

CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases

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

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

Oracle Database: Introduction to SQL

Netezza SQL Class Outline

Database Query 1: SQL Basics

Oracle Database: Introduction to SQL

B) Mean Function: This function returns the arithmetic mean (average) and ignores the missing value. E.G: Var=MEAN (var1, var2, var3 varn);

DBMS / Business Intelligence, SQL Server

Oracle Database 11g SQL

Instant SQL Programming

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

Oracle Database 10g: Introduction to SQL

Oracle Database: Introduction to SQL

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

SAS: A Mini-Manual for ECO 351 by Andrew C. Brod

SAS 9.3 SQL Procedure

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

Creating QBE Queries in Microsoft SQL Server

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

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

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

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

Querying Microsoft SQL Server

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

Testing data warehouses with key data indicators Results with Highspeed

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

Training/Internship Brochure Advanced Clinical SAS Programming Full Time 6 months Program

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

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

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

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

Database Administration with MySQL

Querying Microsoft SQL Server 2012

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Course ID#: W 35 Hrs. Course Content

Course 10774A: Querying Microsoft SQL Server 2012

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals

Information Systems SQL. Nikolaj Popov

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

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

Web Development using PHP (WD_PHP) Duration 1.5 months

Effective Use of SQL in SAS Programming

Querying Microsoft SQL Server 20461C; 5 days

Structured Query Language (SQL)

REPORT GENERATION USING SQL*PLUS COMMANDS

Data Tool Platform SQL Development Tools

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

1 Structured Query Language: Again. 2 Joining Tables

Access 2010: Creating Queries Table of Contents INTRODUCTION TO QUERIES... 2 QUERY JOINS... 2 INNER JOINS... 3 OUTER JOINS...

Saskatoon Business College Corporate Training Centre

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

ETL TESTING TRAINING

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

Essentials of SQL. Essential SQL 11/06/2010. NWeHealth, The University of Manchester

Querying Microsoft SQL Server Course M Day(s) 30:00 Hours

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

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

Advanced SQL Queries for the EMF

Inquiry Formulas. student guide

Aggregating Data Using Group Functions

Data Mining Commonly Used SQL Statements

THE POWER OF PROC FORMAT

Transcription:

SAS SQL #1 SAS Structured Query Language, An Introduction JC Wang What is SQL Language Structured Query Language (SQL), a standardized, widely used language that retrieves / updates data in relational databases. Relation = concept similar to concept of a set in mathematics Relations are represented physically as two-dimensional tables (arranged in rows and columns).

What PROC SQL Does PROC SQL = SAS implementation of Structured Query Language. It can generate reports generate summary statistics retrieve data from tables or views combine data from tables or views create tables, views, and indexes update data values in PROC SQL tables update / retrieve data from database management system (DBMS) tables modify PROC SQL table by adding, modifying, or dropping columns. Comparison of Terminology SQL tables = SAS data file = a file rows = observations = records columns = variables = fields DBMS tables = tables from other vendors which can be accessed through SAS/ACCESS Queries retrieve data from a table, view, or DBMS with results consisting of rows and columns from a table. SQL view contains a stored query (instruction only), i.e., a virtual table SAS PROC SQL null values = missing values.

Syntax of PROC SQL basic use PROC SQL <options>; query-1; query-2;...more queries... QUIT; a query = a run block. Upon submission, SAS executes the query. End PROC SQL with a QUIT since it s interactive. Syntax of a Query from single table SELECT input-columns FROM table WHERE cond-to-subset-input-rows GROUP BY column HAVING cond-to-subset-groups ORDER BY columns; It s a single statement in this order of clauses. SELECT and FROM are required.

SELECT and FROM Clauses SELECT input-columns FROM table; input-columns: a comma-separated ordered list of columns or the wild-card (= all columns in table) table: one-word table (SAS data set) name or two-word name libref.sas-data-set-name (usually the latter) use SELECT DISTINCT a-table-column to query only unique values of the table column Input Columns in SELECT Clause an input column can be a table column a quoted text string a calculated column a column created by a simple CASE expression a column created by a CASE-Operand expression a column created by COALESCE function of columns

Dress Up Input Columns with Attributes input-column <attributes> where attributes are blank-separated column attributes of FORMAT= INFORMAT= LABEL= text-string (or simply text-string ) LENGTH= Use of LABEL= # suppresses the column header. Using Column Alias input-column AS column-alias where column-alias is a valid SAS name used as an alias when referencing it in subsequent calculated column(s) in the calculation, use the alias

Adding Text to Output Codes data test; do r = rank( A ) to rank( Z ); c = byte(r); output; end; run; proc sql; select Character format=$9., r label= # format=2., is, c # from test; quit; Output -------------------- Character 65 is A Character 66 is B Character 67 is C Character 68 is D more output lines here Character 90 is Z Calculated Column created by arithmatic-expression <AS alias> <attributes> where alias is required if it is referenced in subsequent calculated column(s) referencing it by CALCULATED alias

Column Created By CASE Expression created by CASE WHEN cond-1 THEN expr-1 more WHEN-THEN clauses as needed ELSE expr-2 END <AS alias> <attributes> referencing it by CALCULATED alias Column Created By CASE-Operand Expression created by CASE operand WHEN value-1 THEN expr-1 more WHEN-THEN clauses as needed ELSE expr-2 END <AS alias> <attributes> referencing it by CALCULATED alias

Column Created By COALESCE Function Usage: COALESCE(col-1,col-2<,...>) <AS alias> <attributes> returns first non-missing value of the columns; returns missing value if all missing. For example, select Name, coalesce(lowpoint, *Not Available* ) as LowPoint from mylib.continents; select Name, case when LowPoint is missing then *Not Available* else LowPoint end as LowPoint from mylib.continents; Subset Input Table Using WHERE Clause SELECT input-columns FROM table WHERE cond; where cond is expression that makes use of table columns and/or input columns and with comparison operators (symbols or mnemonics), logical operators (symbols or mnemonics) special operators including BETWEEN-AND, CONTAINS, IN, IS NULL/IS MISSING, LIKE, and = truncated string comparison operators (3-letter mnemonics formed by appending 2-letter comparison operators) special operators linking subquery: ANY (subquery), ALL (subquery), and EXISTS (subquery)

Summarizing Data using aggregate functions Aggregate functions (or summary functions) are used to combine columns. If single column is specified then the column statistic is produced; otherwise, row statistics are produced for the columns. Aggregate functions include 1. AVG/MEAN, MIN, MAX, SUM SUMWGT 2. RANGE, STD, STDERR, CV 3. USS, CSS, VAR 4. COUNT, FREQ, N, NMISS 5. T, PRT Sorting Query Results SELECT input-column FROM table ORDER BY sort-columns; where columns is a comma-separated list of columns and each sort-column can be an input-column either by name or by its position (a number) in the input-column list can be a table column but not an input column if it s a calculated column, do NOT use CALCULATED keyword use sort-column DESC for a sort-column to be in descending order