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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

870 Combining an SQL View with a <strong>SAS</strong> Data Set 4 Chapter 30When an SQL view is created from a Pass-Through query, the query’s DBMSconnection in<strong>for</strong>mation is stored with the view. There<strong>for</strong>e, when you reference the SQLview in a <strong>SAS</strong> program, you automatically connect to the correct database, and youretrieve the most current data in the DBMS tables.Combining an SQL View with a <strong>SAS</strong> Data SetThe following example joins <strong>SAS</strong> data with Oracle data that is retrieved by using aPass-Through query in a PROC SQL SELECT statement.In<strong>for</strong>mation about student interns is stored in the <strong>SAS</strong> data file, Samples.TempEmps.The Oracle data is joined with this <strong>SAS</strong> data file to determine whether any of thestudent interns have a family member who works in the CSR departments.To join the data from Samples.TempEmps with the data from the Pass-Throughquery, you assign a table alias (Query1) to the query. Doing so enables you to qualifythe query’s column names in the WHERE clause.options ls=120;title ’Interns Who Are Family Members of Employees’;proc sql;connect to oracle as mydb;%put &sqlxmsg;select tempemps.lastname, tempemps.firstnam, tempemps.empid,tempemps.familyid, tempemps.gender, tempemps.dept,tempemps.hiredatefrom connection to mydb(select * from employees) as query1, samples.tempempswhere query1.empid=tempemps.familyid;%put &sqlxmsg;disconnect from mydb;quit;Output 30.2Combining a PROC SQL View with a <strong>SAS</strong> Data SetInterns Who Are Family Members of Employees 1lastname firstnam empid familyid gender dept hiredate-----------------------------------------------------------------------------SMITH ROBERT 765112 234967 M CSR010 04MAY1998NISHIMATSU-LYNCH RICHARD 765111 677890 M CSR011 04MAY1998When <strong>SAS</strong> data is joined to DBMS data through a Pass-Through query, PROC SQLcannot optimize the query. In this case it is much more efficient to use a <strong>SAS</strong>/<strong>ACCESS</strong>LIBNAME statement. Yet there is another way to increase efficiency: extract theDBMS data, place the data in a new <strong>SAS</strong> data file, assign <strong>SAS</strong> indexes to theappropriate variables, and join the two <strong>SAS</strong> data files.

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

Saved successfully!

Ooh no, something went wrong!