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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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