嘗試將SAS「proc freq」結果導出到Excel文件(xlsx),在Windows上使用帶有SAS 9.4的Enterprise guide 7.12。 下面的代碼示例:使用ODS Excel不正確的SAS頻率表輸出
ODS EXCEL
file='C:\Download\example.xlsx'
STYLE=HtmlBlue
OPTIONS (sheet_interval="none" sheet_name="Results");
data example;
input ins_cd$ 1-2 decl_aatrim $ 4-8 prog $ 10-13 compt $ 15-18;
cards;
02 20153 7646 XC12
02 20153 7646 AB02
02 20153 7646 CC13
02 20153 9999
02 20153 7595 PS03
02 20153 7595 PS04
02 20153 6080 XC12
02 20153 6080 XC15
02 20153 6080 CC18
02 20153 6080 DC08
;
proc sort data=example;
by ins_cd decl_aatrim prog compt;
run;
data example2;
set example;
by ins_cd decl_aatrim prog compt;
if first.prog=1 then do;
test=first.prog;
rank=1;
retain rank 1;
end;
else rank=rank+1;
run;
proc freq data=example2;
tables prog*compt;
run;
ods EXCEL close;
輸出作爲預期在結果觀察者,每個PROG四行像這樣的頻率表:(截斷更少拷貝粘貼和頻率行標籤值大致翻譯):
compt
AB02 CC13 CC18 [...]
prog
6080 Freq 0 0 1 1 0 0 1 1
Pct 0.00 0.00 11.11 11.11 0.00 0.00 11.11 11.11
row pct 0.00 0.00 25.00 25.00 0.00 0.00 25.00 25.00
col.pct 0.00 0.00 100.00 100.00 0.00 0.00 50.00 100.00
7595 Freq 0 0 0 0 0 [...]
[...]
但是當通過消耗臭氧層物質生產的XLSX文件在Excel中打開時,頻率表看起來像這樣:
prog compt
Freq
Pct
row pct
col.pct AB02 CC13 CC18 DC08 PS03 PS04 XC12 XC15 Total
6080 0 0 1 1
0.00 0 11.11 [...]
0.00 0.00 25.00
0.00 0.00 100.00
7595 0
0.00 [...]
,並且具有freq計算的四個單元格合併到每個prog的一個單元格和行中。
這個http://support.sas.com/kb/32/115.html似乎與我的問題有關,但提議的交叉表解決方案不會在Excel中給出所需的輸出。 任何想法?謝謝!
您不應該使用'.xlsx'擴展名而不是'.xls'嗎? – Tom
更正,謝謝。這是來自以前的嘗試。但是輸出在xlsx中不會改變。 –