BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
GertNissen
Barite | Level 11
Try
[pre]
data _null_;
set sashelp.class;
file "c:\temp\file.csv" dsd;
put name +(-1) ';' sex +(-1) ';' age;
run;
[/pre]
deleted_user
Not applicable
Thanks,

The lesson must be "RTFM" :-))
deleted_user
Not applicable
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.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2743 views
  • 0 likes
  • 2 in conversation