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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Statistical Analysis System (SAS)

From novice to tech pro — start learning today.