Proc SQL in SAS Enterprise Guide 4.3

Preview:

DESCRIPTION

 

Citation preview

PROC SQL IN SAS ENTERPRISE GUIDE 4.3Mark TabladilloDecember 12, 2011

(C) 2011 Mark Tabladillo

2

About MarkTab Consultant: Data Mining Architect

SAS since 1991 Microsoft MVP this year Presenting and Publishing since 1998

Data Mining Blog http://www.marktab.net

Twitter @marktabnet

(C) 2011 Mark Tabladillo

3

Purpose Provide basic vocabulary and pointers

for absolute beginners Challenge intermediate-to-advanced

users

(C) 2011 Mark Tabladillo

4

Outline Basics on Enterprise Guide 4.3 PROC SQL

SQL Clauses Order of Operations – Best Practices Joins – Best Practices Macro variables

(C) 2011 Mark Tabladillo 5

BASICS ON SAS ENTERPRISE GUIDE 4.3

(C) 2011 Mark Tabladillo

6

About SAS Enterprise Guide 4.3 Shipped July 2011 New features include

New Program Editor with Autocomplete and Integrated Syntax Help

Explicit SQL Pass-through Option Macro Variables for Conditional

Processinghttp://support.sas.com/documentation/cdl/en/whatsnew/62580/HTML/default/viewer.htm#egwhatsnew43.htm

(C) 2011 Mark Tabladillo

7

SAS Enterprise Guide 4.3 Tutorial http://support.sas.com/documentation/onlinedoc/guide/tut4

3/en/

(C) 2011 Mark Tabladillo

8

Tutorial Topics

(C) 2011 Mark Tabladillo

Enterprise Guide is Client Software

9

SAS EnterpriseGuide

SASon Windows

SASon Mainframe

SASon UNIX

Code

Results

(C) 2011 Mark Tabladillo

The SAS Intelligence Platform Architecture

10

Enterprise Guide is fully integrated with the servers in the SAS 9 environment.

SAS Enterprise Guide

SAS Workspace Server

SAS Stored Process Server

SAS OLAP Server

SAS Metadata Server

(C) 2011 Mark Tabladillo 11

PROC SQLSQL Clauses

(C) 2011 Mark Tabladillo

12

Important in Enterprise Guide

(C) 2011 Mark Tabladillo

13

Autocompletion

(C) 2011 Mark Tabladillo

14

Typical SQL Statement – Six Clauses

SELECT column-1 <, ...column-n>FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

15

How many clauses are required?SELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

16

What is an example of a column?

SELECT column-1 <, ...column-n>FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

17

What is an example of a table?SELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

18

What is an example of an expression?

SELECT column-1 <, ...column-n>FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

19

What does DESC mean?SELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

20

MnemonicSELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n>

<WHERE expression>

<GROUP BY column-1 <, ....column-n>>

<HAVING expression>

<ORDER BY column-1 <DESC><, ... Column-n>>;quit;

SOFEWWORKERSGOHOMEON time!

(C) 2011 Mark Tabladillo 21

PROC SQLOrder of Operations – Best Practices

(C) 2011 Mark Tabladillo

22

Order of Operations SQL is a declarative language

You declare the final product Then, the SQL interpreter decides how to

create that final product

(C) 2011 Mark Tabladillo

23

Why try for one SELECT statement?

SQL is a declarative language You declare the final product Then, the SQL interpreter decides how to

create that final product

(C) 2011 Mark Tabladillo

24

Order of OperationsSELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

1

2

3

4

6

5

(C) 2011 Mark Tabladillo

25

Best Practices?SELECT column-1 <, ...column-n>

FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

1

2

3

4

6

5

(C) 2011 Mark Tabladillo 26

PROC SQLJoins – Best Practices

(C) 2011 Mark Tabladillo

27

JoinsType DescriptionLEFT JOIN One to ManyRIGHT JOIN Many to OneFULL JOIN Many to Many, with MissingCROSS JOIN ProductUNION JOIN ConcatenationNATURAL JOIN Conservative Matching

Recommended:Sams Teach Yourself SQL in 10 Minutes (3rd Edition) by Ben FortaReference:http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473691.htm

(C) 2011 Mark Tabladillo

28

Think Through Join Sources SAS can join

SAS Excel Access Oracle Mainframe Text Files

(C) 2011 Mark Tabladillo

29

Best Practice Rules Typed data is better than non-typed Subset better than the whole Native SQL better than SAS SQL In-memory data is faster than disk data Close to the server is better than far

away – subset before moving SAS sources are better than not

(C) 2011 Mark Tabladillo 30

PROC SQLMacro Variables

(C) 2011 Mark Tabladillo

31

PROC SQL Makes Macro Variables

SELECT column-1 <, ...column-n>INTO macro-variable-specification

< , ... macro-variable-specification>FROM table-1|view-1<, ...table-n|view-n><WHERE expression><GROUP BY column-1 <, ....column-n>><HAVING expression><ORDER BY column-1 <DESC><, ...

Column-n>>;quit;

(C) 2011 Mark Tabladillo

32

What is a Macro Variable? Text Variable Stores Information in Memory Typically scoped to Global Dynamically Generated

Useful as a prequel to a PROC SQL statement

Useful as an Enterprise Guide 4.3 Condition

(C) 2011 Mark Tabladillo

33

Macro Variables as Conditions

(C) 2011 Mark Tabladillo

34

Defining a Macro Condition

(C) 2011 Mark Tabladillo

35

Process Flow Conditions

(C) 2011 Mark Tabladillo

36

Recommended http://support.sas.com Books

Sams Teach Yourself SQL in 10 Minutes (3rd Edition) by Ben Forta

The Little SAS Book for Enterprise Guide 4.2 by Susan J. Slaughter and Lora D. Delwiche

Professional SAS Programmer's Pocket Reference Sixth Edition by Rick Aster

(C) 2011 Mark Tabladillo

37

Conclusion Enterprise Guide 4.3 allows for simple

through advanced processing with PROC SQL

Many resources available: Free SAS tutorials Books People

Recommended