SQL8 Chapter 5 Slides
SQL8 Chapter 5 Slides
1
Section 5.1
2
Objectives
3
Controlling Processing
4
Controlling Processing
Selected options:
continued...
5
Controlling Processing
8
Controlling Processing
Points
Required Rank Award
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
2000 1 free night
in hotel
10000 2 50% discount
on flight
20000 3 free domestic
flight
40000 4 free
international
flight
9
Controlling Processing
10
Controlling Processing
OK
11
Controlling Processing
Output
FlightNumber Date
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
182 01MAR2000
114 01MAR2000
202 01MAR2000
219 01MAR2000
439 01MAR2000
387 01MAR2000
290 01MAR2000
523 01MAR2000
982 01MAR2000
622 01MAR2000
12
Resetting Options
13
Resetting Options
14
Resetting Options
reset nonumber;
select *
from airline.payrollmaster;
Job
EmpID Gender Code Salary DateOfBirth DateOfHire
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
1919 M TA2 $48,126 16SEP1958 07JUN1985
1653 F ME2 $49,151 19OCT1962 12AUG1988
15
Section 5.2
16
Objectives
17
Overview
18
Overview
19
Overview
SAS File Metadata
DICTIONARY.MEMBERS general information about
data library members
DICTIONARY.TABLES detailed information about
data sets
DICTIONARY.COLUMNS detailed information on
variables and their attributes
DICTIONARY.CATALOGS information about catalog
entries
DICTIONARY.VIEWS general information about
data views
DICTIONARY.INDEXES information on indexes
defined for data files 20
Overview
Other Metadata
21
Exploring Dictionary Tables
Partial Log
22
Using Dictionary Information
23
Using Dictionary Information
Output
memname nobs nvar crdate
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
FLIGHTDELAYS 624 8 18MAR00:20:53:16
FLIGHTSCHEDULE 270 4 18MAR00:20:53:17
FREQUENTFLYERS 206 11 18MAR00:20:53:16
INTERNATIONALFLIGHTS 201 4 18MAR00:20:53:16
MARCHFLIGHTS 635 13 18MAR00:20:53:16
MECHANICSLEVEL1 8 3 18MAR00:20:53:17
MECHANICSLEVEL2 14 3 18MAR00:20:53:17
MECHANICSLEVEL3 7 3 18MAR00:20:53:17
PAYROLLCHANGES 6 6 18MAR00:20:53:17
PAYROLLMASTER 148 6 18MAR00:20:53:17
STAFFCHANGES 6 6 18MAR00:20:53:18
STAFFMASTER 148 6 18MAR00:20:53:17
SUPERVISORS 19 3 18MAR00:20:53:18
24
Using Dictionary Information
select memname
from dictionary.columns
where libname='AIRLINE'
and name='EmpID';
25
Using Dictionary Information
Output
memname
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
FLIGHTSCHEDULE
MECHANICSLEVEL1
MECHANICSLEVEL2
MECHANICSLEVEL3
PAYROLLCHANGES
PAYROLLMASTER
STAFFCHANGES
STAFFMASTER
SUPERVISORS
26
Using Dictionary Information
27
Using Dictionary Information
proc tabulate
data=sashelp.vmember
format=8.;
class libname memtype;
keylabel N=' ';
table libname, memtype/
rts=10 misstext='None';
run;
28
Using Dictionary Information
Output
„ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†
‚ ‚ memtype ‚
‚ ‡ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒ‰
‚ ‚CATALOG ‚ DATA ‚ITEMSTOR‚ MDDB ‚ VIEW ‚
‡ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ‰
‚libname ‚ ‚ ‚ ‚ ‚ ‚
‡ƒƒƒƒƒƒƒƒ‰ ‚ ‚ ‚ ‚ ‚
‚AIRLINE ‚ 1‚ 13‚ None‚ None‚ None‚
‡ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ‰
‚MAPS ‚ 3‚ 314‚ None‚ None‚ None‚
‡ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ‰
‚SASHELP ‚ 128‚ 104‚ 2‚ 2‚ 18‚
‡ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ‰
‚SASUSER ‚ 8‚ 80‚ 1‚ None‚ None‚
‡ƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒ‰
‚WORK ‚ 1‚ None‚ 1‚ None‚ None‚
Šƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒŒ 29
Section 5.3
30
Objectives
31
Resolving Symbolic References
This sounds
familiar!
32
...
%let datasetname=payrollmaster;
%let bigsalary=100000;
SYMBOL TABLE
Name Value
datasetname payrollmaster
bigsalary 100000
33
...
SYMBOL TABLE
Name Value
datasetname payrollmaster
bigsalary 100000
select *
from airline.&datasetname
where Salary > &bigsalary;
34
Resolving Symbolic References
SYMBOL TABLE
Name Value
datasetname payrollmaster
bigsalary 100000
select *
from airline.payrollmaster
where Salary > 100000;
35
Creating Macro Variables
36
Creating Macro Variables
37
Creating Macro Variables: Method 1
38
Creating Macro Variables: Method 1
Example
reset noprint;
select avg(salary),
min(salary),
max(salary)
into :mean, :min, :max
from airline.payrollmaster;
%put &mean &min &max;
Log
54079.65 25120.2 155930.6
39
Creating Macro Variables: Method 1
Example
Calculate the average salary of employees with a
particular job code. Store the average in a macro
variable and use the average to display all
employees in that job code who have a salary
above the average. Place the average in a title.
40
Creating Macro Variables: Method 1
Example
%let code=NA1;
select avg(Salary) into :mean
from airline.payrollmaster
where JobCode="&code";
41
Creating Macro Variables: Method 1
Example (continued)
reset print;
title1 "&code Employees Earning Above-Average Salaries";
title2 "Average Salary for &code Employees Is &mean";
select *
from airline.payrollmaster
where Salary > &mean
and
JobCode="&code";
42
Creating Macro Variables: Method 1
Output
NA1 Employees Earning Above-Average Salaries
Average Salary for NA1 Employees Is 58845.08
Job
EmpID Gender Code Salary DateOfBirth DateOfHire
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
1839 F NA1 $60,806 02DEC1968 07JUL1991
1332 M NA1 $59,049 20SEP1968 07JUN1989
1443 F NA1 $59,184 21NOV1966 01SEP1989
43
Creating Macro Variables: Method 2
44
Creating Macro Variables: Method 2
Example
How many frequent flyers are in each of the
three member types (GOLD, SILVER, BRONZE)?
reset noprint;
select MemberType,
count(*) as Frequency
into :memtype1-:memtype3,
:freq1-:freq3
from airline.frequentflyers
group by MemberType;
45
Creating Macro Variables: Method 2
Example (continued)
Log
Member types: BRONZE GOLD SILVER
Frequencies: 61 60 85
46
Creating Macro Variables: Method 3
SEPARATED BY 'delimiter'
FROM ...values from all rows of the
Method 3 extracts
query result, and puts them into a single macro
variable, separated by the specified delimiter.
47
Creating Macro Variables: Method 3
48
Automatic Macro Variables
50
Automatic Macro Variables
Example (continued)
%macro state(st);
proc sql;
create table &st as
select LastName,
FirstName
from airline.staffmaster
where State="&st";
%put NOTE: The table &st has &sqlobs rows.;
51
Automatic Macro Variables
Example (continued)
title1 "&st Employees";
%if &sqlobs > 10 %then %do;
%put NOTE: Only the first 10 rows are displayed.;
title2 "NOTE: Only 10 rows are displayed.";
reset outobs=10;
%end;
select * from &st;
quit;
%mend state;
52
Automatic Macro Variables
Example (continued)
%state(NY)
Log
NOTE: Table WORK.NY created, with 89 rows
and 2 columns.
NOTE: The table NY has 89 rows.
NOTE: Only the first 10 rows are displayed.
WARNING: Statement terminated early due to
OUTOBS=10 option.
53
Automatic Macro Variables
Example (continued)
Output
NY Employees
NOTE: Only 10 rows are displayed.
LastName FirstName
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
APPLE TROY
ARTHUR BARBARA
BAUCOM WALTER
BLALOCK RALPH
BOSTIC MARIE
BOYCE JONATHAN
BRADLEY JEREMY
BRYANT LEONARD
BURNETTE THOMAS 54
CAHILL MARSHALL
Section 5.4
55
Objectives
56
Testing and Performance Options
Example
Display the columns that are retrieved when you
use SELECT * in a query and display any macro
variable resolutions, but do not execute the
query.
58
Testing and Performance Options
Example (continued)
%let datasetname=payrollmaster;
proc sql
feedback
noexec;
select *
from airline.&datasetname;
59
Testing and Performance Options
Example (continued)
Log
NOTE: Statement transforms to:
select PAYROLLMASTER.EmpID, PAYROLLMASTER.Gender,
PAYROLLMASTER.JobCode,
PAYROLLMASTER.Salary, PAYROLLMASTER.DateOfBirth,
PAYROLLMASTER.DateOfHire
from AIRLINE.PAYROLLMASTER;
60
Testing and Performance Options
Example
This is a log from a PROC SQL step with the STIMER
statement option, executing a single query. The first
note concerns the invocation of PROC SQL:
NOTE: The SQL statement used the following resources:
CPU time - 00:00:00.01
Elapsed time - 00:00:00.68
EXCP count - 28
Task memory - 110K (20K data, 90K program)
Total memory - 864K (760K data, 104K program)
61
Testing and Performance Options
Example (continued)
The second note concerns the query itself.
NOTE: The SQL statement used the following resources:
CPU time - 00:00:00.23
Elapsed time - 00:00:03.61
EXCP count - 157
Task memory - 1213K (828K data, 385K program)
Total memory - 2258K (1840K data, 418K program)
62
Testing and Performance Options
Example (continued)
The third note reflects the totals for the procedure.
NOTE: The SQL procedure used the following resources:
CPU time - 00:00:00.25
Elapsed time - 00:00:04.34
EXCP count - 186
Task memory - 1213K (828K data, 385K program)
Total memory - 2258K (1840K data, 418K program)
63
General Guidelines for
Benchmarking Programs
Never use elapsed time for comparison
because it may be affected by concurrent
tasks.
Benchmark two programs in separate SAS
sessions. If benchmarking is done within one
SAS session, statistics for the second
program can be misleading because the SAS
supervisor might have loaded modules into
memory from prior steps.
64
General Guidelines for
Benchmarking Programs
Run each program multiple times and
average the performance statistics.
Use realistic data for tests. Program A could
be better than program B on small tables and
worse on large tables.
65