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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: