[英]Outputting multiple datasets from SAS into one excel output with multiple spreadsheets
[英]Write multiple SAS datasets into one Excel sheet
我正在使用 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;
;
我的懷疑是因為您sheet_interval='none'
在初始ods tagsets.excelxp
上指定sheet_interval='none'
。
和你一樣,第一個例子有這個問題:
ods tagsets.excelxp file="h:\temp\test.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:\temp\test.xls";
proc print data=sashelp.class;
run;
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
有趣的是,如果你刪除第二個,它仍然有效——所以並不是說它不在第一行,而是它是新的選項語句。 我想這會以某種方式重置它。 但在你的情況下,真的沒有理由不在最初的ods tagsets.excelxp
聲明中添加任何這些細節。
ODS EXCEL
不是這樣工作的,它總是在一張紙上。 如果可以的話,我建議在任何情況下都使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.