DATA Step, Macro, Functions and more

Writing data to a csv file without spaces

Reply
N/A
Posts: 0

Writing data to a csv file without spaces

How do I write data to a semicolon sepr. file with no spaces before the semicolon?

the code (example)

data _null_
file "c:\temp\file.csv";
set sashelp.class;
put name';'sex ';'age;
run;

gives the result (please notice the spaces before the semicolon)

Alfred ;M ;14
Alice ;F ;13
Barbara ;F ;13
Carol ;F ;14
Henry ;M ;14


Should it alle be put in to a compressed string or what?
The case is complicated by the fact that char.vars should be in quotes in the output as in this example (but still with no spaces):

"Alfred" ;"M" ;14
"Alice" ;"F" ;13
"Barbara" ;"F" ;13
"Carol" ;"F" ;14
"Henry" ;"M" ;14
SAS Employee
Posts: 174

Re: Writing data to a csv file without spaces

Posted in reply to deleted_user
Try
[pre]
data _null_;
set sashelp.class;
file "c:\temp\file.csv" dsd;
put name +(-1) ';' sex +(-1) ';' age;
run;
[/pre]
N/A
Posts: 0

Re: Writing data to a csv file without spaces

Posted in reply to GertNissen
Thanks,

The lesson must be "RTFM" :-))
N/A
Posts: 0

Re: Writing data to a csv file without spaces

Posted in reply to deleted_user
Geniz is right but not making full use of SAS. Try

data _null_;
set sashelp.class;
file "c:\temp\file.csv" dsd dlm=";" ;
put name sex age;
run;

SAS allows you to specify the delimitter to use with the DSD. Makes life very easy.
Ask a Question
Discussion stats
  • 3 replies
  • 160 views
  • 0 likes
  • 2 in conversation