After you install the formats
that SAS supplies in libraries inside the DB2 database and publish
any custom format definitions that you created in SAS, you can access
the SAS_PUT( ) function with your SQL queries.
If the SQLMAPPUTTO=
system option is set to SAS_PUT and you submit your program from a
SAS session, the SAS SQL processor maps PUT function calls to SAS_PUT( )
function references that DB2 understands.
This example illustrates
how the PUT function is mapped to the SAS_PUT( ) function using
implicit pass-through. The SELECT DISTINCT clause executes inside
DB2, and the processing is distributed across all available data nodes.
DB2 formats the sales values with the $DOLLAR12.2 format and processes
the SELECT DISTINCT clause using the formatted values.
%let mapconn=user=sas1 password=sas31 database=indb;
libname dblib db2 &mapconn;
data dblib.shoes;
set sashelp.shoes;
run;
options sastrace=',,,d' sastraceloc=saslog;
proc sql noerrorstop;
title 'Test SAS_PUT using Implicit PassThru/LIBNAME ';
select distinct
PUT(SALES, Dollar8.2)AS SALES_C from dblib.SHOES;
quit;
These lines are written
to the SAS log.
1726 options sastrace=',,,d' sastraceloc=saslog;
1727
1728 proc sql noerrorstop;
1729 title 'Test SAS_PUT using Implicit PassThru/LIBNAME ';
1730 select distinct
1731 PUT(SALES, Dollar8.2)AS SALES_C from dblib.SHOES;
DB2: AUTOCOMMIT turned ON for connection id 0 1854 1309265953 setconlo 0 SQL
1855 1309265953 du_prep 0 SQL
DB2_363: Prepared: on connection 0 1856 1309265953 du_prep 0 SQL
SELECT * FROM SHOES FOR READ ONLY 1857 1309265953 du_prep 0 SQL
1858 1309265953 du_prep 0 SQL
DB2: COMMIT performed on connection 0. 1859 1309265953 du_comm 0 SQL
1860 1309265953 du_prep 0 SQL
DB2_364: Prepared: on connection 0 1861 1309265953 du_prep 0 SQL
select distinct cast(SAS_PUT(TXT_1."SALES", 'DOLLAR8.2') as char(8))
as SALES_C from SHOES TXT_1
FOR READ ONLY 1862 1309265953 du_prep 0 SQL
1863 1309265953 du_prep 0 SQL
DB2: COMMIT performed on connection 0. 1864 1309265953 du_comm 0 SQL
1865 1309265953 du_exec 0 SQL
DB2_365: Executed: on connection 0 1866 1309265953 du_exec 0 SQL
Prepared statement DB2_364 1867 1309265953 du_exec 0 SQL
1868 1309265953 du_exec 0 SQL
ACCESS ENGINE: SQL statement was passed to the DBMS for fetching data.
1869 1309265953 fetch 0
SQL
1732 quit;