Proc Sql Kelly Hardman Aug. 9, 2007 BMTRY 789. What is Proc Sql? SQL: Structured Query Language It is a procedure that combines the data and proc steps.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

How SAS implements structured programming constructs
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
S ORTING WITH SAS L ONG, VERY LONG AND LARGE, VERY LARGE D ATA Aldi Kraja Division of Statistical Genomics SAS seminar series June 02, 2008.
I OWA S TATE U NIVERSITY Department of Animal Science Modifying and Combing SAS Data Sets (Chapter in the 6 Little SAS Book) Animal Science 500 Lecture.
Performing Queries Using PROC SQL Chapter 1 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Beginning Data Manipulation HRP Topic 4 Oct 19 th 2011.
Introduction to SQL Session 2 Retrieving Data From Multiple Tables.
Biostatistical Methods II PubH 6415 Spring PubH 6415 – Biostatistics I Instructor: Susan Telke (office hours: lecture.
Introduction to SAS ISYS 650. What Is SAS? SAS is a collection of modules that are used to process and analyze data. It began in the late ’60s and early.
SAS PROCs ISYS 650. PROC Statement Syntax PROC name options; Statements statement options; … RUN;
Categorical Data Analysis using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Discuss the Chi Square Test of Independence.
SAS ® Regression Essentials. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
Hash vs Join A case study evaluating the use of the data step hash object to replace a SQL join Geoff Ness Sep 2014.
Basic And Advanced SAS Programming
PROC SQL – Select Codes To Master For Power Programming Codes and Examples from SAS.com Nethra Sambamoorthi, PhD Northwestern University Master of Science.
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
SAS Programming SAS Data Mart. Outline Access different format of data for SAS SAS data mart SAS data manipulation 2.
Topics in Data Management SAS Data Step. Combining Data Sets I - SET Statement Data available on common variables from different sources. Multiple datasets.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
SAS SQL SAS Seminar Series
SAS PROC REPORT PROC TABULATE
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
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.
BMTRY 789 Lecture 3: Categorical Data and Dates Readings – Chapter 3 & 4 Lab Problems 3.1, 3.2, 3.19, 4.1, 4.3, 4.5 Homework – HW 2 Book Problems Due 6/24!
My ODS: Real-World Uses of Modifying Table Templates Steve James Centers for Disease Control and Prevention Atlanta, Ga.
Quantify the Example Data First, code and quantify the data (assign column locations & variable names) Use the sample data to create a data set from the.
Multiple Uses for a Simple SQL Procedure Rebecca Larsen University of South Florida.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
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.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
1 Efficient SAS Coding with Proc SQL When Proc SQL is Easier than Traditional SAS Approaches Mike Atkinson, May 4, 2005.
Chapter 3 “Working With Your Data” concerns programming in the DATA step - putting lines of SAS code between a DATA and PROC statement… Creating new variables.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
1 EPIB 698C Lecture 4 Raul Cruz-Cano Summer 2012.
An Introduction Katherine Nicholas & Liqiong Fan.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
17b.Accessing Data: Manipulating Variables in SAS ®
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
Use the SET statement to: –create an exact copy of a SAS dataset –modify an existing SAS dataset by creating new variables, subsetting (using a subsetting.
Testing Significance of coefficients Usually, first examination of model Does the model including the independent variable provide significantly more information.
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
ODS TAGSETS - a Powerful Reporting Method Derek. 2 Agenda Understanding the tagset How to use tagsets Conclusion.
Four way analysis Nursing home residence Gender Age Death.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 26 By Tasha Chapman, Oregon Health Authority.
1 Ready To Become Really Productive Using PROC SQL? Sunil Gupta Gupta Programming.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Session 1 Retrieving Data From a Single Table
Structured Query Language (SQL)
Title page lifestyle image
PROC SQL, Overview.
Chapter 4 Summary Query.
Introduction to DATA Step Programming SAS Basics II
Combining Data Sets in the DATA step.
S Co-Sponsors by State – May 23, 2014
UNION Operator keywords Displays all rows from both the tables
Hans Baumgartner Penn State University
Presentation transcript:

Proc Sql Kelly Hardman Aug. 9, 2007 BMTRY 789

What is Proc Sql? SQL: Structured Query Language It is a procedure that combines the data and proc steps of traditional SAS code It can “sort, summarize, join, and concatenate datasets, create new variables, and print the results or create a new table to view all in one step!” It can perform these functions quicker and with fewer steps than traditional SAS code

Proc Sql: The Basics Syntax: Title ‘ ‘; Proc Sql; Select columns From table-name Where expression Group By columns Having expression Order By columns; Quit;

Example Data Set Data People; length Name$ 9; length City$ 9; length Occupation$ 12; input Name$ Age Gender$ City$ State$ Occupation$; datalines; Robert 55 M Annapolis MD accountant Susan 24 F Charlotte NC nurse Gary 43 M Denver CO construction Elizabeth 15 F Miami FL student Trey 33 M Seattle WA doctor Hazel 72 F Madison WI retired Amanda 41 F Cleveland OH teacher Victoria 36 F Tucson AZ secretary Dan 61 M Rochester NY fireman Cynthia 52 F Savannah GA housewife Doug 49 M Gulfport MS lawyer Charles 37 M Detroit MI banker ; run;

Selecting All of the Data With traditional code, we would use proc print In proc sql, we use: proc sql; select * from People; quit; Notice the * It is used when selecting all of the columns People is the data set name. If we were using a permanent data set, we would use libname.People

All of the Data Proc Sql – All of the Data NameCityOccupationAgeGenderState RobertAnnapolisaccountant55MMD SusanCharlottenurse24FNC GaryDenverconstruction43MCO ElizabethMiamistudent15FFL TreySeattledoctor33MWA HazelMadisonretired72FWI AmandaClevelandteacher41FOH VictoriaTucsonsecretary36FAZ DanRochesterfireman61MNY CynthiaSavannahhousewife52FGA DougGulfportlawyer49MMS CharlesDetroitbanker37MMI

Selecting Some of the Data To select only certain columns or variables, just write the column names after the select statements Here we just want names, cities, and states: proc sql; select name, city, state from people; quit; Notice the commas between the column names

Some of the Data Proc Sql - Selecting Certain Variables NameCityState RobertAnnapolisMD SusanCharlotteNC GaryDenverCO ElizabethMiamiFL TreySeattleWA HazelMadisonWI AmandaClevelandOH VictoriaTucsonAZ DanRochesterNY CynthiaSavannahGA DougGulfportMS CharlesDetroitMI

Sorting Data With traditional code, we would use a proc sort followed by a proc print In proc sql, we use: proc sql; select name, age, gender from people order by gender, age asc; quit;

Sorted Data Proc Sql - Sorting Data NameAgeGender Elizabeth15F Susan24F Victoria36F Amanda41F Cynthia52F Hazel72F Trey33M Charles37M Gary43M Doug49M Robert55M Dan61M

Analyzing a Subset of Data The where statement is used in proc sql the same way it is used in traditional SAS code Here, we only want the names and occupations of the females: proc sql; select name, occupation from people where gender in ('F'); quit;

Subset of Data Proc Sql - Subset of Data NameOccupation Susannurse Elizabethstudent Hazelretired Amandateacher Victoriasecretary Cynthiahousewife

Creating a New Variable Traditionally, to create a new variable, we would have to use a series of if-then statements in the data step With proc sql: proc sql; select name, age, case when age le 20 then 'young' when age le 54 then 'middle-aged' else 'old' end as Category from people order by Age asc, Category asc; quit;

New Variable Proc Sql - Creating a New, Conditional Variable NameAgeCategory Elizabeth15young Susan24middle-aged Trey33middle-aged Victoria36middle-aged Charles37middle-aged Amanda41middle-aged Gary43middle-aged Doug49middle-aged Cynthia52middle-aged Robert55old Dan61old Hazel72old

Creating a New Table Equivalent of creating a new data set from the old data set Here, we create the table EastCoast from the table People proc sql; create table EastCoast as select name, occupation, state from people where state in ('NC','MD','FL','NY','GA'); select * from EastCoast; quit;

New Table Proc Sql - Creating a New Table NameOccupationState RobertaccountantMD SusannurseNC ElizabethstudentFL DanfiremanNY CynthiahousewifeGA

References Ronk, Katie Minten, Steve First, David Beam. “An Introduction to Proc SQL” SUGI Paper pdf Vecchione, Phil “Proc SQL” E8FcgdygFIJ: pective/tipsNtricks.pub/1/PROC%2520SQL %2520Talk_12_.ppt+proc+sql&hl=en&ct=cl nk&cd=8&gl=us&client=firefox-a

Questions?