Goal: export an entire SAS dataset to a tab-delimited text file using a data step.
Problem: In every example that I can find, such as this one, one must specify ev
You need to use both a variable list and format list to use the _ALL_
keyword in the PUT
statement and not have it generate the names. The format list does not need to contain any actual formats but it cannot be empty. So this code will create a CSV file, without column headers.
data _null_;
file 'want.csv' dsd ;
set have ;
put (_all_) (+0) ;
run;
If you do want column headers there are a couple of methods you could use. Here is one that uses PROC TRANSPOSE
to generate a dataset with the variable names. This can be used to write the header row and then the above code can be used with just the addition of the MOD
keyword to the FILE
statement to append the data records.
proc transpose data=have(obs=0) out=names ;
var _all_;
run;
data _null_;
file 'want.csv' dsd ;
set names end=eof;
put _name_ @ ;
if eof then put;
run;