The EXPORT procedure does not write out all the variables listed for the KEEP= data set option when the PUTNAMES=NO statement is included


PROC EXPORT does not write out all the variables listed for the KEEP= data set option when the PUTNAMES=NO statement is also used. For example, two variables are listed for the KEEP= data set option, but only one variable is written to the file. Here is a syntax example that can cause this issue; in this case, only the AGE variable is written to the class.csv file:

proc export data=sashelp.class(keep=name age)
outfile='c:\temp\class.csv' dbms=csv replace;
putnames=no;
run;

The workaround is to use the KEEP= data set option in a DATA step prior to PROC EXPORT. Then use PROC EXPORT with the PUTNAMES=NO statement to create an external file that does not include variable names as column names in the first row. Here is the syntax to use for the workaround:

data class;
set sashelp.class (keep=name age);
run;
proc export data=class
outfile='c:\temp\class2.csv' dbms=csv replace;
putnames=no;
run;