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._¤t_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;
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.
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.
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.