@js5 wrote:
SAS is running on a server. It fetches the data from a remote server and exports the .csv into SAS' workdir (I am using filename temp). I do not think that network bandwidth is the issue, as the download speed goes up-and-down, indicative of network transfer waiting for something.
The reason I am using %ds2csv instead of proc export is the fact that the latter does not apply sufficient quoting for values with line breaks in them.
A more likely reason for the download speed to go up and down is competition for the network bandwidth from other processes.
To force SAS to add quotes around values it does not think needs them you can just use the ~ modifier in the PUT statement. If the remote system does not mind if the numeric variables have quotes around them (the SAS INPUT statement when using the DSD option on the INFILE statement does not mind them for example) then you could just add the quotes around everything.
put (_all_) (~);
Which means your export step could be as simple as:
proc transpose data=&indsn(obs=0) out=names;
var _all_;
run;
data _null_;
file &outfile dsd lrecl=1000000;
length _name_ $32 _label_ $256 ;
set names;
_label_=coalescec(_label_,_name_);
put _label_ ~ @ ;
run;
data _null_;
file &outfile mod dsd lrecl=1000000;
set &indsn;
put (_all_) (~);
run;
Results
"Name","Sex","Age","Height","Weight"
"Alfred","M","14","69","112.5"
"Alice","F","13","56.5","84"
"Barbara","F","13","65.3","98"
"Carol","F","14","62.8","102.5"
"Henry","M","14","63.5","102.5"
"James","M","12","57.3","83"
If you NEED to only add the ~ for the character variables then use PROC CONTENTS to get the list of file names so you have the TYPE of the variable also to allow you to determine when to add the ~ modifier.
filename csv temp;
%let outfile=csv;
%let indsn=sashelp.class;
proc contents data=&indsn out=contents noprint;
run;
proc sql noprint;
select quote(trim(coalesce(label,name)))
, catx(' ',nliteral(name)
,case when type=2 then '~' else ' ' end
)
into :headers separated by ','
, :varlist separated by ' '
from contents
order by varnum
;
quit;
data _null_;
file &outfile dsd lrecl=1000000;
put %sysfunc(quote(%superq(headers),%str(%')));
run;
data _null_;
file &outfile mod dsd lrecl=1000000;
set &indsn;
put &varlist;
run;
Results
"Name","Sex","Age","Height","Weight"
"Alfred","M",14,69,112.5
"Alice","F",13,56.5,84
"Barbara","F",13,65.3,98
"Carol","F",14,62.8,102.5
"Henry","M",14,63.5,102.5
"James","M",12,57.3,83
... View more