You can do this using option:
delimiter=" ";
for example:
data credit;
set sashelp.credit(obs=10);
run;
proc print;
proc export data=credit
outfile="/home/u61950255/Files/data.csv"
dbms=csv
replace;
delimiter=" ";
putnames=NO;
run;
But beware that it would cause problem when you have space in between the data in the same column. @santhosh
Look at the data from csv file generated by above code with delimiter=" ";
Your desired output does not look like something usable. You appear to have three variables named No, particular, and amount. But some of your data rows appear to have more than 3 values on them.
Normally in a delimited text file (like a CSV file) you have to quote values that contain the delimiter.
So, depending on which value the space belongs to, your file might look like this:
No particular amount 1 "I BOOKS" 5000 2 "A PLANE" 3000 3 "B DOUBLE ROOL" 2000 4 "II STATENAORY" 1000 5 "A PEN" 500 6 "B PENCIL" 500
SAS can generate that type of file using a simple data step with the DSD option of the FILE statement.
data _null_;
set have;
file 'mytext_file.txt' dsd dlm=' ';
if _n_=1 then put 'No particular amount';
put no particular amount;
run;
Your question is a bit underspecified so my answer based on some assumptions.
data work.have;
infile datalines dsd dlm=' ';
input no particular:$40. amount;
datalines;
1 "I BOOKS" 5000
2 " A PLANE" 3000
3 " B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 " A PEN" 500
6 " B PENCIL" 500
;
proc export
data=work.have
outfile= "c:\temp\want.csv"
dbms=csv
;
quit;
c:\temp\want.csv opened with a text editor
Leading spaces do not translate well into a delimited file.
To preserve them when reading a file like you could try using the $CHAR informat instead of the normal $ informat.
data have;
infile cards dsd dlm=' ' truncover;
input No particular :$char20. amount;
cards;
1 "I BOOKS" 5000
2 " A PLANE" 3000
3 " B DOUBLE ROOL" 2000
4 "II STATENAORY" 1000
5 " A PEN" 500
6 " B PENCIL" 500
;
But to write that back out you will need to NOT use the DSD option on the FILE statement.
Which means you cannot use PROC EXPORT.
So instead just use the $QUOTE. format to add quotes around every string variable, just in case it has any embedded space.
data _null_;
file 'want.csv';
set have;
if _n_=1 then put 'No particular amount';
put no particular amount;
format _character_ $quote.;
run;
No particular amount 1 "I BOOKS" 5000 2 " A PLANE" 3000 3 " B DOUBLE ROOL" 2000 4 "II STATENAORY" 1000 5 " A PEN" 500 6 " B PENCIL" 500
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.