You
can embed a SAS LIBNAME statement or a
SAS/ACCESS LIBNAME statement
in a view by using the USING LIBNAME clause. When PROC SQL executes
the view, the stored query assigns the libref. For
SAS/ACCESS librefs,
PROC SQL establishes a connection to a DBMS. The scope of the libref
is local to the view and does not conflict with any identically named
librefs in the SAS session. When the query finishes, the libref is
disassociated. The connection to the DBMS is terminated and all data
in the library becomes unavailable.
The advantage of embedded
librefs is that you can store engine-host options and DBMS connection
information, such as passwords, in the view. That, in turn, means
that you do not have to remember and reenter that information when
you want to use the libref.
Note: The USING LIBNAME clause
must be the last clause in the SELECT statement. Multiple clauses
can be specified, separated by commas.
In the following example,
the libref OILINFO is assigned and a connection is made to an ORACLE
database:
proc sql;
create view sql.view1 as
select *
from oilinfo.reserves as newreserves
using libname oilinfo 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.
The following example
embeds a SAS LIBNAME statement in a view:
proc sql;
create view sql.view2 as
select *
from oil.reserves
using libname oil 'SAS-data-library';