Take the 2-minute tour ×

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 every variable in the data step following the PUT statement. Isn't there a simple method to just ask for "all" of the variables?

I have already tried using PUT _ALL_, but that includes the variable names in every row of the output, instead of just outputtin the values.

share|improve this question
1) Why not PROC EXPORT with DBMS=TAB? 2) Is order of variables important? –  vasja Apr 28 at 18:25
@vasja, I happen to want also to specify the ENCODING option in my datastep, and I'm not aware of such a capability in PROC EXPORT. –  zkurtz Apr 28 at 18:29
Zkurtz... include everything you are trying to do... I suspect a data step may not be able to do what you want. –  Keni Apr 28 at 18:30
You may be able to do so in the filename. –  Joe Apr 28 at 18:32

2 Answers 2

If you want to do it in a data step, AND don't want to specify things, but really don't want PROC EXPORT making decisions for you, AND have data that's reasonably easily specified (nothing fancy like dates you want in a special format), you can do this.

proc sql;
select name into :namelist separated by ' ' 
from dictionary.columns
where libname='SASHELP' and memname='CLASS'; *these are the libname/dataset name you want;

filename blah temp;
data _null_;
set sashelp.class;
file blah dlm='09'x;
put &namelist.;

You can customize it some depending on your needs by modifying the sql query (such as if you have a set of variables with _date perhaps you could modify it to add name||' :date9.' in the sql query for those.

Note that the libname/memname/name fields in dictionary.columns are typically upper case. They are not always upper case, I don't think, but they almost always are. (Some RDBMSs for example can override this, I believe).

share|improve this answer
working through this -- just noticed that evidently it is essential that 'SASHELP' and 'CLASS' are uppercase. –  zkurtz Apr 28 at 20:01
curious about the function of the 'filename blah temp' line –  zkurtz Apr 28 at 20:03
I'm just lazy. That's me writing out to a temporary file I won't have to delete later. :) temp as a keyword on a filename statement means it's written to your work directory. –  Joe Apr 28 at 20:05
Correct - the memname / name dictionary fields are not always uppercase, even for SAS datasets. Something to keep in mind.. –  RawFocus Apr 29 at 8:41

@Joe's brilliant and quick as always.

For reference, many options, including ENCODING are possible with FILENAME. Those should be usable anywhere file path is allowed.

FILENAME myfile "E:\test.csv" encoding=wlatin2;

share|improve this answer
I tested this, and it looks like it works correctly. –  Joe Apr 28 at 19:41

Your Answer


