You are on page 1of 10

SAS Techies

info@sastechies.com
http://www.sastechies.com
 Reading and Writing data to Other DBMS’s

◦ SAS Access Libname Method


◦ SAS Connect Pass Thru SQL (RSPT)
◦ Proc Dbload / Proc Access
◦ Which one to Choose and when ??

SAS Techies 2009 11/13/09 2


 The LIBNAME statement
enables you to assign SAS
librefs to DBMS objects such
as schemas and databases.
After a database is associated
with a libref, you can use a
SAS two-level name to specify
LIBNAME libref oracle <connection-options>
any table or view in the
<LIBNAME-options>; database and then work with
the table or view as you
DBCOMMIT=n
PRESERVE_COL_NAMES=NO | YES
would with a SAS data set.
PRESERVE_TAB_NAMES=NO | YES

SAS Techies 2009 3


Proc sql;
Create table orcl.ap as
Select * from perm.airports;
libname orcl oracle user=scott Quit;
password=tiger path="ORCL";
Proc sql;
Options sastrace=‘,,,d’; Create table orcl.ap1 as
Select * from perm.admitjune A,
data orcl.admit; perm.admit B
input x y; Where A.id=B.id;
cards;
Quit;
12
34
56 libname orcl db2 user=scott
; password=tiger path=“DB2";
run;
Proc sql;
data orcl.ap; Create table orcl.ap1 as
set perm.airports; Select * from orcl.ap A, db2.ap B
run; Where A.id=B.id;
Quit;

SAS Techies 2009 11/13/09 4


 The Pass-Through Facility
enables you to interact
with a data source using
its native SQL syntax
without leaving your SAS
session. The SQL
statements are passed
directly to the data source
for processing.

SAS Techies 2009 5


Creating SAS dataset from Creating a DBMS table from two
DBMS table DBMS tables

proc sql;
proc sql; connect to oracle (user=scott
connect to oracle (user=scott password=tiger path="ORCL");
password=tiger path="ORCL"); execute(create table Sharad as
create table work.cool as select A.*
select * from connection to oracle from info A, descr B
(select A.* where A.FlightID=B.FlightID) by
from info A, descr B oracle;
where A.FlightID=B.FlightID ); execute(COMMIT) by oracle;
disconnect from oracle; disconnect from oracle;
quit;
quit;

SAS Techies 2009 11/13/09 6


proc dbload dbms=oracle  The ACCESS and
data=perm.admit; *SAS dataset; DBLOAD procedures
user=scott; support indirect access
password=tiger;
to DBMS data. These
path='ORCL';
procedures are no longer
table=newemp; *DBMS Table;
the recommended
commit=100;
errlimit=10;
method for accessing
load; run; DBMS data, but they
continue to be supported
for the database systems
and environments on
which they were
available for SAS Version
6.

SAS Techies 2009 7


SAS Techies 2009 11/13/09 8
SAS Techies 2009 11/13/09 9
 Usually the fastest and most direct
method.. An exception to this is
when you need to use non-ANSI
standard SQL.  Pass-Through Facility statements
enable the DBMS to optimize
queries, particularly when you
 Only way to Join data on Two join tables.
different DBMS.
 The DBMS optimizer can take
 Significantly fewer lines of SAS code. advantage of indexes on DBMS
columns to process a query more
 You do not need to know the SQL quickly and efficiently.
language of your DBMS.
 Pass-Through Facility statements
 The LIBNAME statement provides enable the DBMS to optimize
more control over DBMS operations queries when the queries have
such as locking, spooling, and data summary functions.
type conversion through the use of
LIBNAME and data set options.  Pass-Through Facility statements
give you better access to DBMS
 The engine can optimize the return codes.
processing of joins and WHERE
clauses by passing these operations
directly to the DBMS.  The Pass-Through Facility accepts
all the extensions to ANSI SQL
 The engine can pass some functions that are provided by your DBMS
directly to the DBMS for processing.

SAS Techies 2009 11/13/09 10

You might also like