Hi,
Here is an example using ODS CSVALL to convert SAS to CSV file:
x |
aaaa |
1 |
Okay |
According to Maxim 1:
data test;
x="aaaa"; output;
x="+1"; output;
x="Okay"; output;
run;
ods csvall file="test.csv" options(DOC="HELP" Quoted_columns="1");
title "Test title!!";
proc print data=test noobs;
run;
ods csvall close;
Bart
How did you inspect the csv file? Do NOT open it with Excel, use a text editor.
It's the same when using NOTEPAD to open the file:
If your goal is to have a simple csv file, don't use ODS. Both of these methods work:
data _null_;
set test;
file "~/test1.csv";
if _n_ = 1 then put "x";
put x;
run;
proc export
data=test
file="~/test2.csv"
dbms=csv
replace
;
run;
And will perform MUCH better with larger datasets.
Thanks!
Yes, both of the methods work. Just I also need to add a title to the CSV file.
According to Maxim 1:
data test;
x="aaaa"; output;
x="+1"; output;
x="Okay"; output;
run;
ods csvall file="test.csv" options(DOC="HELP" Quoted_columns="1");
title "Test title!!";
proc print data=test noobs;
run;
ods csvall close;
Bart
Cool!!
Thank you Bart!
That is a BUG in the CSVALL ODS destination. You should report it to SAS support.
Not only does it not generate the proper CSV file, it also seems to have some lasting impact on the normal HTML output used in the RESULT window in Display Manager.
If I run this code once:
data test;
x="aaaa"; output;
x="+1.0"; output;
x="Okay"; output;
run;
filename csv temp;
ods csvall file=csv;
proc print data=test noobs;
run;
ods csvall close;
data _null_;
infile csv ;
input;
list;
run;
The PROC PRINT displayed in the Results Window looks normal:
If I then run the same code a second time the Results output has switched to using some monospaces font. And the output looks like the output previously sent to CSVALL, with the missing + and the extra unneeded quotes around the other value.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.