The USING clause enables you to store DBMS connection
information in a view by embedding the
SAS/ACCESS LIBNAME statement inside the view. When PROC SQL executes
the view, the stored query assigns the libref and establishes the
DBMS connection using the information in the LIBNAME statement. The
scope of the libref is local to the view, and will not conflict with
any identically named librefs in the SAS session. When the query
finishes, the connection to the DBMS is terminated and the libref
is deassigned.
The
USING clause must be the last clause in the CREATE VIEW statement.
Multiple LIBNAME statements can be specified, separated by commas.
In the following example, a connection is made and the libref ACCREC
is assigned to an ORACLE database.
create view proclib.view1 as
select *
from accrec.invoices as invoices
using libname accrec oracle
user=username
pass=password
path='dbms-path';
For more information
about the
SAS/ACCESS LIBNAME
statement, see the
SAS/ACCESS
documentation for your DBMS.
Note: Starting in SAS System 9,
PROC SQL views, the pass-through facility, and the
SAS/ACCESS LIBNAME statement are the preferred
ways to access relational DBMS data;
SAS/ACCESS views are no longer recommended. You can convert existing
SAS/ACCESS views to PROC SQL views
by using the CV2VIEW procedure.
For more information,
see Chapter 33, “CV2VIEW Procedure” in SAS/ACCESS for Relational Databases: Reference.
You can also embed a
SAS LIBNAME statement in a view with the USING clause, which enables
you to store SAS libref information in the view. Just as in the embedded
SAS/ACCESS
LIBNAME statement, the scope of the libref is local to the view, and
it will not conflict with an identically named libref in the SAS session.
create view work.tableview as
select * from proclib.invoices
using libname proclib
'SAS-library';