These examples are based
on these assumptions:
-
There is a DeptInfo table on the
DBMS that has all of your department information.
-
You have a SAS data set with join
criteria that you want to use to retrieve certain rows from the DeptInfo
table.
-
You have another SAS data set with
updates to the DeptInfo table.
Here are the librefs
and temporary tables that 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;
To perform a homogeneous
join on the DBMS, the next example shows how to use a heterogeneous
join with a temporary table. It does this instead of reading the DBMS
table into SAS to perform the join. Using the previously created table,
SAS data is copied into the temporary table to perform 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 tab
where info.deptno = tab.deptno;
/* remove the rows for the next example */
exec(delete from session.temptab1) by db2;
quit;
In this example, transaction
processing on the DBMS occurs using a temporary table. It does this
instead of using either DBKEY= or MULTI_DATASRC_OPT=IN_CLAUSE with
a SAS data set as the transaction table.
proc append base=temp.temptab1 data=saslib.transdat;
run;
proc sql;
connect to db2 (connection=global);
exec(update dschema.deptinfo d set deptno = (select deptn from
session.temptab1)
where d.dname = (select dname from session.temptab1)) by db2;
quit;