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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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