What ODS CSV produces is not a real CSV file. It adds too many quotes and it also adds an extra line at the end. But it sounds like what you want is not a real CSV file either. Fortunately it is easy with SAS to produce both a real CSV file and what you want with just a couple of simple steps.
First let's get some test data to use. For example the first three records in SASHELP.CLASS.
data test; set sashelp.class(obs=3); run;
Now let's set the output location. I will use a temp file for this demonstration.
filename csv temp;
The first line of the CSV file is usually the variable names (column headers). You can generate that easily using a couple of steps.
proc transpose data=test(obs=0) ;
var _all_;
run;
data _null_;
file csv dsd ;
set &syslast end=eof;
put _name_ @;
if eof then put ;
run;
Now to write the data lines we just add one more data step.
data _null_;
file csv dsd mod;
set test ;
put (_all_) (+0);
run;
To check if the result is in the proper format let's run a simple data step to show the lines from the output file back into the SAS log.
data _null_;
infile csv;
input;
put _infile_;
run;
So for our little three observation test case the result is the well formed CSV file below. Note that there are no unneeded quote characters or extra blank lines.
Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
To add all of those extra quote characters that you requested you just need to add the ~ modifier to the put statements.
So in the step that writes the variable names you would use this PUT statement.
put _name_ ~ @;
And in the step that writes the variable values you would use this PUT statement.
put (_all_) (~) ;
With those changes the resulting file will look like this:
"Name","Sex","Age","Height","Weight"
"Alfred","M","14","69","112.5"
"Alice","F","13","56.5","84"
"Barbara","F","13","65.3","98"
... View more