From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Proc SQL in SAS Enterprise Guide 4.3
1. PROC SQL
IN SAS ENTERPRISE
GUIDE 4.3
Mark Tabladillo
December 12, 2011
2. About MarkTab
2
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
3
Provide basic vocabulary and pointers for
absolute beginners
Challenge intermediate-to-advanced users
(C) 2011 Mark Tabladillo
4. Outline
4
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. (C) 2011 Mark Tabladillo 5
BASICS ON SAS
ENTERPRISE GUIDE
4.3
6. About SAS Enterprise Guide
6
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 Processing
http://support.sas.com/documentation/cdl/en/whatsnew/62580/HTML/default/viewer.htm#egwhatsnew43
.htm
(C) 2011 Mark Tabladillo
7. SAS Enterprise Guide 4.3
7
Tutorial
http://support.sas.com/documentation/onlinedoc/guide/tut43/en/
(C) 2011 Mark Tabladillo
9. Enterprise Guide is Client
Software
SAS
on Windows
SAS
on Mainframe
SAS
on UNIX
SAS Enterprise
Guide
(C) 2011 Mark Tabladillo
9
10. The SAS Intelligence Platform
Architecture
Enterprise Guide is fully integrated with the
servers in the SAS 9 environment.
SAS Metadata Server
SAS OLAP
Server
SAS Enterprise Guide SAS Stored Process Server
SAS Workspace Server
(C) 2011 Mark Tabladillo
10
14. Typical SQL Statement – Six
14
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
15
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
16
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?
17
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
18
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?
19
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. Mnemonic
20
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;
SO
FEW
WORKERS
GO
HOME
ON time!
(C) 2011 Mark Tabladillo
21. (C) 2011 Mark Tabladillo 21
PROC SQL
Order of Operations – Best Practices
22. Order of Operations
22
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
23
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 Operations
24
5 SELECT column-1 <, ...column-n>
1
FROM table-1|view-1<, ...table-n|view-n>
2 <WHERE expression>
3 <GROUP BY column-1 <, ....column-n>>
4 <HAVING expression>
6 <ORDER BY column-1 <DESC><, ...
Column-n>>;
quit;
(C) 2011 Mark Tabladillo
25. Best Practices?
25
5 SELECT column-1 <, ...column-n>
1
FROM table-1|view-1<, ...table-n|view-n>
2 <WHERE expression>
3 <GROUP BY column-1 <, ....column-n>>
4 <HAVING expression>
6 <ORDER BY column-1 <DESC><, ...
Column-n>>;
quit;
(C) 2011 Mark Tabladillo
26. (C) 2011 Mark Tabladillo 26
PROC SQL
Joins – Best Practices
27. Joins
27
Type Description
LEFT JOIN One to Many
RIGHT JOIN Many to One
FULL JOIN Many to Many, with Missing
CROSS JOIN Product
UNION JOIN Concatenation
NATURAL JOIN Conservative Matching
Recommended:
Sams Teach Yourself SQL in 10 Minutes (3rd Edition) by Ben Forta
Reference:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/def
ault/viewer.htm#a002473691.htm
(C) 2011 Mark Tabladillo
28. Think Through Join Sources
28
SAS can join
SAS
Excel
Access
Oracle
Mainframe
Text Files
(C) 2011 Mark Tabladillo
29. Best Practice Rules
29
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. (C) 2011 Mark Tabladillo 30
PROC SQL
Macro Variables
31. PROC SQL Makes Macro
31
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?
32
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
36. Recommended
36
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
37
Enterprise Guide 4.3 allows for simple through
advanced processing with PROC SQL
Many resources available:
FreeSAS tutorials
Books
People
(C) 2011 Mark Tabladillo