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.
@Joe's brilliant and quick as always.
For reference, many options, including
ENCODING
are possible withFILENAME
. Those should be usable anywhere file path is allowed.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.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 addname||' :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).
In a datastep I find when I just want to get a list of the values using
For example:
/* or to look at a few records or modify for specific conditions */
You need to use both a variable list and format list to use the
_ALL_
keyword in thePUT
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.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 theMOD
keyword to theFILE
statement to append the data records.