将多个SAS数据集写入一个Excel表格



我正在使用SAS企业指南7.15。我想将几个数据集导出到多个excel表格(每个表格中的多个表)。我正在使用ODS,即使我设置了sheet_interval="none",在两个表之后,它打破了页面,并将下一个表推到另一个excel工作表。

这是我代码中的一个例子,这里是导出2个表,稍后我想在同一个工作表中添加20个表:

%macro table_1;
proc report data=table_1 out=sheet_1 headline split='#' spacing=1 nowd missing
style(summary)={font_weight=bold}
columns 

segment     
diff        
cnt_old         
cnt_new
;


compute before _page_/style=[font_size=3 font_weight=bold foreground=white background=Dark Blue];
line "table 1";
line ' ';
line 'Number of Customers';
endcomp;
compute after;
endcomp
run;
%mend table_1;
%macro table_3;
proc report data=table_3 out=sheet_1 headline split='#' spacing=1 nowd missing
style(summary)={font_weight=bold}
columns 

FinalRiskRating 
diff
cnt_old         
cnt_new;


compute before _page_/style=[font_size=3 font_weight=bold foreground=white background=Dark Blue];
line "table 3";

endcomp;
compute after;
endcomp
run;
%mend table_3;
%table_1; %table_3;

%let shk = table_1 + table_3;
ods path work.temptemp(update) sasuser.templat(update) sashelp.tmplmst(read);
ods path show;
Options mprint mlogic symbolgen nobyline;
ods listing close;
%macro b;
%do i=1 %to 2;
%let mshk=%scan(&shk., &i.,+);
/*ods tagsets.excelxp options(SHEET_INTERVAL='NONE' PAGEBREAK="NO"  sheet_name="sheet1" ABSOLUTE_COLUMN_WIDTH='8' AUTOFIT_HEIGHT='yes' embed_titles_once = 'yes' embedded_titles='yes');*/
ods tagsets.excelxp options(sheet_interval="none" sheet_name="sheet1" ABSOLUTE_COLUMN_WIDTH='8' AUTOFIT_HEIGHT='yes' embed_titles_once = 'yes' embedded_titles='yes');
%&mshk.;
%end;
%mend b;
ods tagsets.excelxp file="&reportlocation";
%b;
ods tagsets.excelxp close;
ods _all_ close;
;

我怀疑是因为您没有在初始ods tagsets.excelxp上指定sheet_interval='none'

和你的一样,第一个例子也有这个问题:

ods tagsets.excelxp  file="h:temptest.xls";
ods tagsets.excelxp options(sheet_interval='none');
proc print data=sashelp.class;
run;
ods tagsets.excelxp options(sheet_interval='none');
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;

但这是预期的工作:

ods tagsets.excelxp options(sheet_interval='none') file="h:temptest.xls";
proc print data=sashelp.class;
run;
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
有趣的是,如果你删除了第二个,它仍然有效——所以它并不是不在第一行,而是新的选项语句。我想这在某种程度上重置了它。但是在你的情况下,真的没有理由不把这些细节放在初始的ods tagsets.excelxp语句中。

ODS EXCEL不是这样工作的,它总是在一张纸上。如果可以的话,我建议你在任何情况下都使用它。

最新更新