Professional Documents
Culture Documents
ANN
BECKER
01JAN1999:00:00:00
2003
CHRIS
DOBSON
13FEB2001:00:00:00
100
ALLEN
PARK
24SEP2001:00:00:00
10392
BETTY
JOHNSON
28NOV2001:00:00:00
3832
NANCY
PAUL
01JUN2001:00:00:00
1202
Overview
Syntax
Options
Specifying Columns
Row Subsetting
Creating Views
Creating SAS Datasets
Date Constants and Conversion
Error Messages
Notes:
The SELECT FROM CONNECTION allows you to specify SAS formats,
labels etc.
The subquery is passed to the DBMS unchanged except for macro
substitution.
SSID=DB2-subsystem-id
SERVER=DRDA-server
DRDA server
AUTHID=authorization-id
DB2 authorization id
Example:
proc sql ;
connect to db2(ssid=ssc1);
. . .
Note:
These options are the same as the ones for the LIBNAME statement,
except they are coded in a different place.
The PROC SQL Pass-Through Facility
sas select
*/
Notes:
Everything inside the parentheses refers to DB2 names, values. (BLUE)
Everything outside the parentheses is SAS. (RED)
The PROC SQL Pass-Through Facility
Resulting Output
DB2 Pass Through Query
FNAME
LNAME
CLAIMDT
CLAIMS
ANN
BECKER
01JAN1999:00:00:00
2003
CHRIS
DOBSON
13FEB2001:00:00:00
100
ALLEN
PARK
24SEP2001:00:00:00
10392
BETTY
JOHNSON
28NOV2001:00:00:00
3832
NANCY
PAUL
01JUN2001:00:00:00
1202
265
;
run;
Notes:
The entire DBMS table is returned to SAS (inefficient).
The DBMS will sort the EMPLOYEE table if necessary.
The PROC SQL Pass-Through Facility
10
FNAME
LNAME
JACK
CHRIS
LINDA
LYNN
BRENDA
KELLER
FOSTER
GILBERT
GOGGIN
WASHINGTON
STORENO
EMPNUMBER
33312
31381
33312
35618
31381
127
177
199
200
216
11
An Efficiency Problem
Merging a very small SAS file with a very large DBMS table can download
entire tables only to discard most rows because they don't match.
Is there some way to tell SAS, only to bring down matching rows?
12
Syntax:
data sasdataset;
set sasdataset1;
set sasdataset2(dbkey=index) key=dbkey;
Notes:
13
Notes:
Only matching records are retrieved from the DBMS table (efficient).
The DBKEY variable may or may not be an index on the DBMS.
The PROC SQL Pass-Through Facility
14
FNAME
LNAME
JACK
CHRIS
LINDA
LYNN
BRENDA
KELLER
FOSTER
GILBERT
GOGGIN
WASHINGTON
STORENO
EMPNUMBER
33312
31381
33312
35618
31381
127
177
199
200
216
Note:
DBKEY should only be used when SAS dataset is very small.
15
16
. . .
Notes:
The entire DBMS table is sometimes downloaded to SAS (expensive)
The PROC SQL Pass-Through Facility
17
Obs
1
2
3
4
5
FNAME
LNAME
JACK
CHRIS
LINDA
LYNN
BRENDA
KELLER
FOSTER
GILBERT
GOGGIN
WASHINGTON
STORENO
33312
31381
33312
35618
31381
EMPNUMBER
127
177
199
200
216
18
. . .
Notes:
This is much more efficient when SAS dataset is small.
The PROC SQL Pass-Through Facility
19
Obs
1
2
3
4
5
FNAME
LNAME
JACK
CHRIS
LINDA
LYNN
BRENDA
KELLER
FOSTER
GILBERT
GOGGIN
WASHINGTON
STORENO
33312
31381
33312
35618
31381
EMPNUMBER
127
177
199
200
216
20
21
22
23
24
A Better Program
Keeping only the columns needed as an input option will result in a shorter
query.
libname msalib odbc dsn=mdbtest;
options sastrace=',,,d' sastraceloc=saslog;
proc sort data=msalib.benefits(keep=lname fname)
out=benefit2 nodupkey;
by lname fname;
run;
25