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.

<strong>SAS</strong>/<strong>ACCESS</strong> Interface to DB2 Under z/OS 4 Examples 493SQL step. The global connection then persists across <strong>SAS</strong> DATA steps and evenmultiple PROC SQL steps, as shown in this example:libname temp db2 connection=global;proc sql;connect to db2 (connection=global);exec (declare global temporary table temptab1like other.table on commit PRESERVE rows) by db2;quit;At this point, you can refer to the temporary table by using the Temp libref or theCONNECTION=GLOBAL option with a PROC SQL step.Terminating a Temporary TableYou can drop a temporary table at any time, or allow it to be implicitly dropped whenthe connection is terminated. Temporary tables do not persist beyond the scope of asinge connection.ExamplesThese examples assume there is a DeptInfo table on the DBMS that has all of yourdepartment in<strong>for</strong>mation. They also assume that you have a <strong>SAS</strong> data set with joincriteria that you want to use to get certain rows out of the DeptInfo table, and another<strong>SAS</strong> data set with updates to the DeptInfo table.These librefs and temporary tables are used.libname saslib base ’my.sas.library’;libname dept db2 connection=global schema=dschema;libname temp db2 connection=global schema=SESSION;/* Note that temporary table has a schema of SESSION */proc sql;connect to db2 (connection=global);exec (declare global temporary table temptab1(dname char(20), deptno int)on commit PRESERVE rows) by db2;quit;This example demonstrates how to take a heterogeneous join and use a temporarytable to per<strong>for</strong>m a homogeneous join on the DBMS (as opposed to reading the DBMStable into <strong>SAS</strong> to per<strong>for</strong>m the join). Using the table created above, the <strong>SAS</strong> data iscopied into the temporary table to per<strong>for</strong>m the join.proc append base=temp.temptab1 data=saslib.joindata;run;proc sql;connect to db2 (connection=global);select * from dept.deptinfo info, temp.temptab1 tabwhere info.deptno = tab.deptno;/* remove the rows <strong>for</strong> the next example */exec(delete from session.temptab1) by db2;quit;

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

Saved successfully!

Ooh no, something went wrong!