SAS 数据集输出到EXCEL 代码
%macro printoutexcel(lib=);
%let today = %upcase(&SYSDATE9.);
%let todayt = %sysfunc(today(),yymmddn8.)T%sysfunc(compress(&systime.,:));
data dts;
set sashelp.vtable (where=(libname=upcase("&lib"))) ;
run;
proc sql noprint;
select memname, memlabel into :l_dsets separated by '|', :l_dslabels separated by '|'
from dts;
quit;
ods listing close;
ods excel
%if %upcase(&lib)=OUTPUTDM %then %do;
file="&root.\QC\EditChecks\&protocol EditCheck listings_&todayt..xlsx"
%end;
%else %if %upcase(&lib)=COMPARE %then %do;
file="&root.\QC\DataListings\&protocol compare_&datesp..xlsx"
%end;
%else %if %upcase(&lib)=OUTPUT %then %do;
file="&root.\QC\DataListings\&protocol mm listings_&todayt..xlsx"
%end;
%else %if %upcase(&lib)=OUTPUTPM %then %do;
file="&root.\QC\DataListings\&protocol pm listings_&todayt..xlsx"
%end;
%else %do;
file="&root.\QC\DataListings\&protocol dm listings_other&todayt..xlsx"
%end;
STYLE=excel
options(Embedded_Titles="yes"
center_horizontal = "yes"
orientation= "landscape"
fittopage = "yes"
autofilter="all"
row_repeat = "1-3"
frozen_headers= ""
flow='tables'
formulas='on'
index="on");
%let i=1;
%let l_dset=%scan(&l_dsets,&i,|);
%let l_dslabel=%scan(%bquote(&l_dslabels),&i,|);
%do %while ( &l_dset ^= () );
ods excel options(sheet_name="&l_dset." );
PROC REPORT DATA=&LIB..&l_dset nowd headline headskip split='|' missing
Style(header)=[ cellspacing = 3
borderwidth = 2
bordercolordark = black
background=grey
foreground=white
just=center
vjust=center
]
Style(column)=[ cellspacing = 3
borderwidth = 2
bordercolordark = black
background=white
/* just=center*/
vjust=center
]
;
define _all_ / style(column)={tagattr='format:@ '};
define _char_ /style(column)={tagattr='type: char '};
RUN;
%let i=%eval(&i+1);
%let l_dset=%scan(&l_dsets,&i,|);
%let l_dslabel=%scan(%bquote(&l_dslabels),&i,|);
%end;
ods excel close;
ods listing;
%mend;
%let today = %upcase(&SYSDATE9.);
%let todayt = %sysfunc(today(),yymmddn8.)T%sysfunc(compress(&systime.,:));
data dts;
set sashelp.vtable (where=(libname=upcase("&lib"))) ;
run;
proc sql noprint;
select memname, memlabel into :l_dsets separated by '|', :l_dslabels separated by '|'
from dts;
quit;
ods listing close;
ods excel
%if %upcase(&lib)=OUTPUTDM %then %do;
file="&root.\QC\EditChecks\&protocol EditCheck listings_&todayt..xlsx"
%end;
%else %if %upcase(&lib)=COMPARE %then %do;
file="&root.\QC\DataListings\&protocol compare_&datesp..xlsx"
%end;
%else %if %upcase(&lib)=OUTPUT %then %do;
file="&root.\QC\DataListings\&protocol mm listings_&todayt..xlsx"
%end;
%else %if %upcase(&lib)=OUTPUTPM %then %do;
file="&root.\QC\DataListings\&protocol pm listings_&todayt..xlsx"
%end;
%else %do;
file="&root.\QC\DataListings\&protocol dm listings_other&todayt..xlsx"
%end;
STYLE=excel
options(Embedded_Titles="yes"
center_horizontal = "yes"
orientation= "landscape"
fittopage = "yes"
autofilter="all"
row_repeat = "1-3"
frozen_headers= ""
flow='tables'
formulas='on'
index="on");
%let i=1;
%let l_dset=%scan(&l_dsets,&i,|);
%let l_dslabel=%scan(%bquote(&l_dslabels),&i,|);
%do %while ( &l_dset ^= () );
ods excel options(sheet_name="&l_dset." );
PROC REPORT DATA=&LIB..&l_dset nowd headline headskip split='|' missing
Style(header)=[ cellspacing = 3
borderwidth = 2
bordercolordark = black
background=grey
foreground=white
just=center
vjust=center
]
Style(column)=[ cellspacing = 3
borderwidth = 2
bordercolordark = black
background=white
/* just=center*/
vjust=center
]
;
define _all_ / style(column)={tagattr='format:@ '};
define _char_ /style(column)={tagattr='type: char '};
RUN;
%let i=%eval(&i+1);
%let l_dset=%scan(&l_dsets,&i,|);
%let l_dslabel=%scan(%bquote(&l_dslabels),&i,|);
%end;
ods excel close;
ods listing;
%mend;