@Puspita_1 wrote:
Hi Is that possible to remove the space by using any other approach.
Your required csv format is a bit unusual which is why I assume there isn't anything ready-made available. Using SAS you can always write your own code to exactly get what you want.
data work.class;
length row_num 8;
set sashelp.class;
if _n_=2 then call missing(of _all_);
if _n_=3 then call missing(name, height);
format height 16.4;
row_num=_n_;
run;
%macro MyDs2csv(
inds=,
outfile=,
header=Y
);
filename codegen temp;
data _null_;
stop;
file codegen;
run;
%local lib ds;
%let lib=%upcase(%scan(work.&inds,-2));
%let ds =%upcase(%scan(work.&inds,-1));
/* generate code */
%if %sysfunc(substr(%upcase(&header),1,1))=Y %then
%do;
data _null_;
file codegen mod;
set sashelp.vcolumn(where=(libname="&lib" and memname="&ds")) end=last;
if _n_=1 then put 'if _n_=1 then do;';
put "put '" name @;
if not last then put +(-1) ",' @;" ;
else put +(-1) "';" / "end;";
run;
%end;
data _null_;
file codegen mod;
set sashelp.vcolumn(where=(libname="&lib" and memname="&ds")) end=last;
retain hold '@';
if type='char' then
do;
put 'if not missing(' name +(-1) ') then put ''"'' ' name '+(-1) ''"'' ' hold ';' 'else put ''""'' ' hold ';' ;
end;
else
do;
put 'if not missing(' name +(-1) ') then put ' name '+(-1) ' hold ';' ;
end;
if not last then put "put ',' @;";
else put "put;";
run;
/* execute generated code */
data _null_;
file "&outfile";
set &inds;
%include codegen /source2;
run;
filename codegen clear;
%mend;
%MyDs2csv(inds=work.class,outfile=c:\temp\test.csv);
... View more