Just as with a SAS data set you can use the DROP= and
KEEP= data set options to prevent retrieving unneeded columns from
your DBMS table.
In this example the
KEEP= data set option causes the
SAS/ACCESS engine to select only
the SALARY and DEPT columns when it reads the MYDBLIB.EMPLOYEES table.
libname mydblib db2 user=testid password=testpass database=testdb;
proc print data (keep=salary dept);
where dept='ACC024';
quit;
The DBMS generates SQL
that is similar to this:
SELECT "SALARY", "DEPT" FROM EMPLOYEES
WHERE(DEPT="ACC024")
Without the KEEP option,
the DBMS processes SQL that is similar to this code:
SELECT * FROM EMPLOYEES WHERE(DEPT="ACC024")
This results in all
columns from the EMPLOYEES table being read in to SAS.
The DROP= data set option
is a parallel option that specifies columns to omit from the output
table. Keep in mind that the DROP= and KEEP= data set options are
not interchangeable with the DROP and KEEP statements. Use of the
DROP and KEEP statements when selecting data from a DBMS can result
in retrieval of all column into SAS, which can seriously impact performance.
For example, this code
results in all columns from the EMPLOYEES table being retrieved into
SAS. When creating the output data set, the KEEP statement is applied.
libname mydblib db2 user=testid password=testpass database=testdb;
data temp;
set mydblib.employees;
keep salary;
run;
Here is how you can
use the KEEP= data set option to retrieve only the SALARY column.
data temp;
set mydblib.employees(keep=salary);
run;