To make full use of
temporary tables, the CONNECTION=GLOBAL connection option is necessary.
You can use this option to establish a single connection across SAS
DATA step and procedure boundaries. The LIBNAME statement and the
SQL pass-through facility can also share this connection. Because
a temporary table only exists within a single connection, you must
be able to share this single connection among all steps that reference
the temporary table. The temporary table cannot be referenced from
any other connection.
The type of temporary
table that is used for this processing is created using the DECLARE
TEMPORARY TABLE statement with the ON COMMIT PRESERVE clause. This
type of temporary table lasts for the duration of the connection—unless
it is explicitly dropped—and retains its rows of data beyond
commit points.
DB2 places all global
temporary tables in the SESSION schema. Therefore, to reference these
temporary tables within SAS, you must explicitly provide the SESSION
schema in pass-through SQL statements or use the SCHEMA= LIBNAME option
with a value of SESSION.
Currently, the only
supported way to create a temporary table is to use a PROC SQL pass-through
statement. To use both the SQL pass-through facility and librefs to
reference a temporary table, you need to specify a LIBNAME statement
before the PROC SQL step. This enables the global connection to persist
across SAS steps, even multiple PROC SQL steps, as shown in this example.
libname temp db2 database=sample user=myuser password=mypwd
schema=SESSION connection=global;
proc sql;
connect to db2 (datasrc=sample user=myuser pwd=mypwd connection=global);
execute (declare global temporary table temptab1 like other.table
on commit PRESERVE rows not logged) by db2;
quit;
At this point, you can
refer to the temporary table by using the libref Temp or by using
the CONNECTION=GLOBAL option with a PROC SQL step.