Exporting a comma delimited text file using Proc Export in SAS.

How can I write an export command which gives me the same result as a manual export in SAS. When I do the manual export each record is on a separate line.  When I try using Proc Export my output is one continuous line.  I am trying to output a comma delimited text file.
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?
Hi there Morinia,

Can I suggest a different approach.  Use ODS - it is much simpler.

filename csvFile    "<your complete path and file name here>";
ods CSVALL file=csvFile;

title ; 
footnote ;
proc print data=<your sas dataset to output as CSV> noobs label;
ods CSVALL close;
filename csvFile clear;

Open in new window

CSVALL is the ODS name to use to produce  csv output onto the given file.
csvFile is any file name (max 8 characters) you choose, I use this name because it describes what I am going to do and only lasts a very short time.

If you have an active title it will come out at the top of the csv file.  In most cases you will not want to have that extraneous text on line 1 so use the null title statement.

On the proc print statement use  "label"  to have your variable labels used as column headings in the output text file.  If you don't have "label" it uses the variable name as column headings.

Inside the print proc (before the run statement), you can specify something like
var  date customer address balance;

Open in new window

to specify the variables (and the order of the variables) you want in the csv file. Otherwise you get all the variables.

You can also specify something like
where  (date > "1 jan 2018"d);

Open in new window

to only provide a subset of the data.

Additionally you can use a format statement within the proc print to apply column formats for the csv file.

Note: unless you use ODS to turn off normal printing you will also get a printed copy of the data set to verify the data in the csv file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.