BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Filipvdr
Pyrite | Level 9

Hello,

 

I got the following code which exports a .csv file.

The problem is for blank character values i'm getting ;" "; a space.

How to get rid of this space, i want to keep the quotes.

 

Thanks! 

filename  exprt "/opt/sas/config/Lev1/SASApp/Userdata/ELYSE/Gebouwen_&t_org_id._&current_datetime..csv" encoding="utf-8";

data _null_;
	file exprt dsd dlm=";";
    set temp ;
    put _label_ @;
run;
data _null_;
  set "QUERY_export gebouwen"n;
  file exprt dsd dlm=";" mod;
  put _ALL_ (~);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Filipvdr,

 

You can add a "@" line-hold specifier to the PUT statement, then remove the blanks by modifying the content of the _FILE_ variable and finally write the modified text to the output file with a second PUT statement.

 

Example using a SASHELP dataset:

data _null_;
set sashelp.heart(firstobs=500 obs=505);
file print dsd dlm=';';
put (_all_) (~) @;
_file_=tranwrd(_file_,'" "','""');
put;
run;

Result:

"Alive";"";".";"Female";"40";"63.25";"119";"82";"156";"99";"0";".";"184";"Desirable";"High";"Normal";"Non-smoker"
"Alive";"";".";"Female";"35";"60.5";"108";"82";"128";"99";"5";".";".";"";"Normal";"Normal";"Light (1-5)"
"Alive";"";".";"Male";"49";"67.5";"169";"88";"152";"121";"0";".";"246";"High";"High";"Overweight";"Non-smoker"
"Alive";"";".";"Male";"32";"66.25";"203";"82";"134";"150";"45";".";"179";"Desirable";"Normal";"Overweight";"Very Heavy (> 25)"
"Alive";"";".";"Female";"45";"66";"127";"96";"148";"96";".";".";".";"";"High";"Normal";""
"Alive";"";".";"Female";"32";"60";"108";"62";"130";"99";"0";".";".";"";"Normal";"Normal";"Non-smoker"

 

Also note the added parentheses around _all_ to correct the first PUT statement.

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @Filipvdr,

 

You can add a "@" line-hold specifier to the PUT statement, then remove the blanks by modifying the content of the _FILE_ variable and finally write the modified text to the output file with a second PUT statement.

 

Example using a SASHELP dataset:

data _null_;
set sashelp.heart(firstobs=500 obs=505);
file print dsd dlm=';';
put (_all_) (~) @;
_file_=tranwrd(_file_,'" "','""');
put;
run;

Result:

"Alive";"";".";"Female";"40";"63.25";"119";"82";"156";"99";"0";".";"184";"Desirable";"High";"Normal";"Non-smoker"
"Alive";"";".";"Female";"35";"60.5";"108";"82";"128";"99";"5";".";".";"";"Normal";"Normal";"Light (1-5)"
"Alive";"";".";"Male";"49";"67.5";"169";"88";"152";"121";"0";".";"246";"High";"High";"Overweight";"Non-smoker"
"Alive";"";".";"Male";"32";"66.25";"203";"82";"134";"150";"45";".";"179";"Desirable";"Normal";"Overweight";"Very Heavy (> 25)"
"Alive";"";".";"Female";"45";"66";"127";"96";"148";"96";".";".";".";"";"High";"Normal";""
"Alive";"";".";"Female";"32";"60";"108";"62";"130";"99";"0";".";".";"";"Normal";"Normal";"Non-smoker"

 

Also note the added parentheses around _all_ to correct the first PUT statement.

Filipvdr
Pyrite | Level 9
Thanks, works perfect!
Ksharp
Super User
data have;
 set sashelp.class;
 if _n_=1 then call missing(sex,age);
run;


proc transpose data=have(obs=0) out=temp;
var _all_;
run;
proc sql noprint;
select catt("'",quote(strip(_name_)),"'") into :varname separated by '||";"||' from temp;
select catt('quote(strip(',_name_,'))') into :catx separated by '||";"||' from temp;
quit;
data _null_;
 file 'c:\temp\want.csv';
 set have;
 length _varname _temp $ 200;
 _varname=&varname.;
 _temp=&catx.;
 if _n_=1 then put _varname;
 put _temp;
run;

Ksharp_0-1702385298811.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1336 views
  • 0 likes
  • 3 in conversation