The EXPORT procedure omits the first KEEP= variable from text-based file output when WHERE= precedes KEEP= in the DATA= option


When you use PROC EXPORT to export a SAS® data set to a text-based file format and the DATA= option contains both a WHERE= and a KEEP= data set option, the first variable specified in the KEEP= list is omitted from the output file if the WHERE= option appears before the KEEP= option.

Here is an example:

/* Sample dataset */
data class;
set sashelp.class;
if sex='M' then indic=1;
run;
 
/* Only INDIC is included in the generated PUT statement. */
/* The first KEEP= variable (NAME) is omitted from the exported file. */
proc export data=class (where=(indic) keep=name indic)
outfile="c:\tests\test.txt";
run;
 
In this scenario, the variable NAME is not included in the generated output file, even though it is specified in the KEEP= list.

The issue affects text-based exports, including the following:
  • DBMS=CSV
  • DBMS=DLM
  • DBMS=TAB

The issue affects SAS® 9.4M6 (TS1M6) and SAS® 9.4M9 (TS1M9).

Cause

When PROC EXPORT generates the DATA step used for a text file export, it incorrectly handles data set options when WHERE= precedes KEEP=. As a result, the first variable in the KEEP= list is omitted from the generated PUT statement and is not written to the output file.

Workaround

To work around this issue, specify the KEEP= option before the WHERE= option in the DATA= statement.

Here is an example:

proc export data=class (keep=name indic where=(indic))
outfile="c:\tests\test.txt";
run;

With this option ordering, all variables specified in the KEEP= list are correctly included in the generated DATA step and the exported file.

A fix for this issue is available in SAS 9.4M9.