Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS proc export to CSV: how to add double quotes

Tags:

csv

sas

New to this, so apologies. I have a file in SAS that I need to export as a CSV and I need to add double quotes to all fields. How can I accomplish this? Thanks in advance.

like image 575
Scott Grayson Avatar asked Aug 29 '14 16:08

Scott Grayson


2 Answers

There are many ways to create a CSV file from SAS. Using proc export won't wrap every field in double-quotes, so the easiest one that will do this is the %ds2csv() macro. This assumes you have SAS 9.2 or later. The documentation for it can be found here:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002683390.htm

An example of running it:

%ds2csv(data=sashelp.retail, runmode=b, csvfile=c:\class.csv);

Produces:

"Retail sales in millions of $","DATE","YEAR","MONTH","DAY"
"$220","80Q1","1980","1","1"
"$257","80Q2","1980","4","1"
"$258","80Q3","1980","7","1"
like image 64
Robert Penridge Avatar answered Sep 22 '22 12:09

Robert Penridge


Here is another one using data step

data _null_;
    file 'data_want.csv' dsd dlm = ',';
    set data_have;
    if _n_ = 1 then put @1 "variables name to input"; /* Add variable names */
    put (_all_) (~);
run;
like image 37
xjf Avatar answered Sep 22 '22 12:09

xjf