SAS Studio 3.8
SAS 9.4M6
PROC EXPORT - data has no embedded delimiters.
PROC EXPORT, with embedded delimiters (demo2.csv)
Different versions may have different specifications, that being said, what you're describing is not the default SAS behaviour many of us would expect so something else is the issue.
What happens if you run the exact same code I did, replacing the path to something that makes sense for you?
proc export data=sashelp.class outfile='/home/fkhurshed/demo.csv'
dbms=csv
replace;
run;
data class;
set sashelp.class;
if name in ('Alfred', 'Jane') then name = 'My, Name';
run;
proc export data=class outfile='/home/fkhurshed/demo2.csv'
dbms=csv
replace;
run;
*check versions;
proc product_status;run;
Remove the LABEL option from PROC EXPORT.
If you want the column headers in the text file to use different values than the names of the variable then rename the variables.
Thank you Tom for your advice. It did the magic. However it solved the main problem which is the double quotes and also created another one which we avoided using the Label. (Main-Land) coded as Main_Land
Renaming the variables (perhaps in the notepad or Excel) after Proc Export could be done outside programming environment. However, to accomplish the task accordingly, everything has to be within the programming environment.
Is there anyway to avoid this problem. i mean an alternative to make the variable appear in form of Main-Land instead of Main_Land
Thank you once again.
If you set VALIDVARNAME option to ANY then those labels could be variable names. Note you are still limited to 32 bytes for the variable name. Example:
options validvarname=any;
proc export data=sashelp.class(obs=3 rename=(name='Main-Land'n))
dbms=csv file=csv replace
;
delimiter=';' ;
run;
It is not that hard to write a CSV file without using PROC EXPORT. A simple data step will do it. You can add a second step to first write the header row.
proc transpose data=HAVE(obs=0) out=names;
var _all_;
run;
data _null_;
file 'myfile.csv' dsd dlm=';' ;
length _label_ $256 _name_ $32;
set names ;
_label_=coalescec(_label_,_name_);
put _label_ @@;
run;
data _null_;
file 'myfile.csv' dsd dlm=';' mod ;
set have;
put (_all_) (+0);
run;
data b1;
do sample = 1 to 15;
do unit = 1 to 3;
if unit = 1 then seq = "A";
else if unit = 2 then seq = "B";
else if unit = 3 then seq = "C";
output;
end;
end;
run;
proc export data = b1 outfile = "C:\Users\Documents\My SAS Files\9.4\
My_Programmes\ran.csv" dbms=dlm label replace;
delimiter = ';'; run;
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.