13.07.2015 Views

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The LIBNAME Statement <strong>for</strong> <strong>Relational</strong> <strong>Databases</strong> 4 LIBNAME Statement Syntax <strong>for</strong> <strong>Relational</strong> <strong>Databases</strong> 91connection in<strong>for</strong>mation (user name, password, and data source) that is provided in theembedded LIBNAME statement.proc sql;create view sasuser.myview asselect dname from oralib.deptusing libname oralib oracleuser=scott pw=tiger datasrc=orsrv;quit;Note: You can use the USING LIBNAME syntax to embed LIBNAME statements inSQL views. For more in<strong>for</strong>mation about the USING LIBNAME syntax, see the PROCSQL topic in the Base <strong>SAS</strong> Procedures Guide. 4Assigning a Libref with a <strong>SAS</strong>/<strong>ACCESS</strong> LIBNAME StatementThe following statement creates a libref, MYDBLIB, that uses the <strong>SAS</strong>/<strong>ACCESS</strong>interface to DB2:libname mydblib db2 ssid=db2a authid=testid server=os390svr;The following statement associates the <strong>SAS</strong> libref MYDBLIB with an Oracledatabase that uses the SQL*Net alias AIRDB_REMOTE. You specify the SCHEMA=option on the <strong>SAS</strong>/<strong>ACCESS</strong> LIBNAME statement to connect to the Oracle schema inwhich the database resides. In this example Oracle schemas reside in a database.libname mydblib oracle user=testuser password=testpasspath=airdb_remote schema=hrdept;The AIRDB_REMOTE database contains a number of DBMS objects, includingseveral tables, such as STAFF. After you assign the libref, you can reference the Oracletable like a <strong>SAS</strong> data set and use it as a data source in any DATA step or <strong>SAS</strong>procedure. In the following SQL procedure statement, MYDBLIB.STAFF is thetwo-level <strong>SAS</strong> name <strong>for</strong> the STAFF table in the Oracle database AIRDB_REMOTE:proc sql;select idnum, lnamefrom mydblib.staffwhere state=’NY’order by lname;quit;You can use the DBMS data to create a <strong>SAS</strong> data set:data newds;set mydblib.staff(keep=idnum lname fname);run;You can also use the libref and data set with any other <strong>SAS</strong> procedure. Thisstatement prints the in<strong>for</strong>mation in the STAFF table:proc print data=mydblib.staff;run;This statement lists the database objects in the MYDBLIB library:proc datasets library=mydblib;quit;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!