
PROC REPORT基礎(chǔ)
1 PROC REPORT語法
PROC REPORT data= SAS-data-set options ;
COLUMNS variable_1 …. variable_n;
DEFINE variable_1;
DEFINE variable_2;
. . .
DEFINE variable_n;
COMPUTE blocks
BREAK … ;
RBREAK … ;
RUN;
COLUMNS:指定輸出到報表的列
DEFINE:上述列的格式等
COMPUTE:計算模塊
BREAK / RBREAK:生成合計,或報表其它類型的格式。
PROC REPORT的選項Options有很多,下面介紹幾個常用的:
DATA= 指定做報表的數(shù)據(jù)集
PROMPT= PROMPT模式
NOWINDOWS= 不輸出到結(jié)果
REPORT = 指定一個存儲的報表來生成新報表
OUTREPT= 指定新路徑來存放報表
OUT= 建立新數(shù)據(jù)集
HEADLINE 在報表變量標題和內(nèi)容間生成一個水平分隔線
HEADSKIP 在報表變量標題和內(nèi)容間生成一行空格
2 先生成一個基本的報表
先生成數(shù)據(jù):
data mnthly_sales;
length zip $ 5 cty $ 8 var $ 10;
input zip $ cty $ var $ sales;
label zip="Zip Code"
cty="County"
var="Variety"
sales="Monthly Sales";
datalines;
52423 Scott Merlot 186.
52423 Scott Chardonnay 156.61
52423 Scott Zinfandel 35.5
52423 Scott Merlot 55.3
52388 Scott Merlot 122.89
52388 Scott Chardonnay 78.22
52388 Scott Zinfandel 15.4
52200 Adams Merlot 385.51
52200 Adams Chardonnay 246
52200 Adams Zinfandel 151.1
52200 Adams Chardonnay 76.24
52199 Adams Merlot 233.03
52199 Adams Chardonnay 185.22
52199 Adams Zinfandel 95.84
;
run;
Proc Report生成最基本的報表:
proc report data=mnthly_sales
headline headskip ;
title1 "Simple Report";
column cty zip var sales;
define cty / display width=6 'County/Name';
define zip / display;
define var / display;
define sales / display format=6.2 width=10;
run;
這里的define后面的’/’,其后面有很多選項來對變量格式,輸出方式等進行設(shè)置,其選項如下:
GROUP:分組顯示
DISPLAY:一般顯示
ANALYSIS:其值用于計算或統(tǒng)計
ORDER:按其值排序顯示
ACROSS:交叉顯示
COMPUTED:其值在compute塊里計算得到
結(jié)果:
3 使用order,按指定變量名排序顯示
proc report data=mnthly_sales
headline headskip ;
title1 "Simple Report";
column cty zip var sales;
define cty / order width=6 'County/Name';
define zip / display;
define var / display;
define sales / display format=6.2 width=10;
run;
結(jié)果:
4 group分組顯示
proc report data=mnthly_sales nofs
headline headskip ;
title1 "Simple Report";
column cty zip var sales;
define cty / group width=6 'County/Name';
define zip / group;
define var / group order=freq descending;
define sales / display format=6.2 width=10;
run;
結(jié)果:
5 analysis,統(tǒng)計量求和
proc report data=mnthly_sales nofs
headline headskip ;
title1 "Simple Report";
column cty zip sales;
define cty / group width=6 'County/Name';
define zip / group;
define sales / analysis sum format=6.2 width=10;
run;
結(jié)果:
6 求多個統(tǒng)計量
proc report data=mnthly_sales nofs
headline headskip ;
title1 "Simple Report";
column cty zip sales sales=mean_sales;
define cty / group width=6 'County/Name';
define zip / group;
define sales / analysis sum format=6.2 width=10 'sum';
define mean_sales / analysis mean format=6.2 width=10 'Mean of/Sales';
run;
結(jié)果:
7 如果你想讓某變量的每一個值都作為一列,那就要用到across。這里要注意的是,有across選項的var,在column時后面加了一個’,’,從而將其后面的變量的數(shù)據(jù)直接放到across變量下。。
proc report data=mnthly_sales nofs headline headskip;
title1 "Cross Tab Report (Across Type)";
column cty zip var,sales;
define cty / group width=6 'County/Name';
define zip / group;
define var / across order=freq descending '- Grape Variety -';
define sales / analysis sum format=6.2 width=10 'Revenue';
run;
結(jié)果:
這里,變量variety的每一個值都成為了新的列
8 BREAK與RBREAK,對分組后的報表匯總
proc report data=mnthly_sales nofs headline headskip;
title1 "Report with Breaks";
column cty zip var,sales;
define cty / group width=6 'County/Name';
define zip / group;
define var / across order=freq descending '- Grape Variety -';
define sales / analysis sum format=6.2 width=10 'Revenue';
break after cty / ol skip summarize suppress;
rbreak after / dol skip summarize;
run;
結(jié)果:
這里說明一下BREAK與RBREAK后面的選項:
OL 匯總上方加一條線
DOL匯總上方加兩條線
UL匯總下方加一條線
DUL 匯總下方加兩條線
summarize 對每組進行匯總
skip 加入一空白行
suppress 在匯總行不顯示組名
9 compute塊,計算統(tǒng)計變量,這個以后將專門介紹
proc report data=mnthly_sales nofs headline headskip;
title1 "Report with Row Sums (Computed Type)";
column cty zip var,sales row_sum;
define cty / group width=6 'County/Name';
define zip / group;
define var / across order=freq descending '- Grape Variety -';
define sales / analysis sum format=6.2 width=10 'Revenue';
define row_sum / computed format=comma10.2 'Total';
break after cty / ol skip summarize suppress;
rbreak after / dol skip summarize;
compute row_sum;
row_sum = sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);
endcompute;
run;
結(jié)果:
Compute塊是以compute開始,endcompute為結(jié)尾,可以計算出很多復雜的數(shù)據(jù)。這里的_C*_表示第幾列的變量,例如_C3_表示第三列,_C#_代表最后一行。這里的_C7_和_C8_是多余的,但不影響結(jié)果。
10 proc report與ODS,以后會詳細介紹。這里用ODS輸出report過程結(jié)果,方法很簡單,就是將上面的report代碼放入ods語句之間。
ods listing close;
ods rtf file = ‘c:sugi30.rtf’;
上面的proc report過程代碼放在這里就行
ods rtf close;
即:
ods listing close;
ods rtf file = 'c:sugi30.rtf';
proc report data=mnthly_sales nofs headline headskip;
title1 "Report with Row Sums (Computed Type)";
column cty zip var,sales row_sum;
define cty / group width=6 'County/Name';
define zip / group;
define var / across order=freq descending '- Grape Variety -';
define sales / analysis sum format=6.2 width=10 'Revenue';
define row_sum / computed format=comma10.2 'Total';
break after cty / ol skip summarize suppress;
rbreak after / dol skip summarize;
compute row_sum;
row_sum = sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);
endcompute;
run;
ods rtf close;
結(jié)果:
11 report設(shè)置style,讓報表更炫一點。這個以后也會詳細介紹
ods listing close;
ods rtf file = 'c:sugi30.rtf';
proc report data=mnthly_sales nofs headline headskip
style(header)={background=lightskyblue foreground=black}
style(column)={background=lightcyan foreground=black};
title1 "Report with Row Sums (Computed Type)";
column cty zip var,sales row_sum;
define cty / group width=6 'County/Name';
define zip / group;
define var / across order=freq descending '- Grape Variety -';
define sales / analysis sum format=6.2 width=10 'Revenue';
define row_sum / computed format=comma10.2 'Total';
break after cty / ol skip summarize suppress;
rbreak after / dol skip summarize;
compute row_sum;
row_sum = sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);
endcompute;
run;
ods rtf close;
結(jié)果:
數(shù)據(jù)分析咨詢請掃描二維碼
若不方便掃碼,搜微信號:CDAshujufenxi
LSTM 模型輸入長度選擇技巧:提升序列建模效能的關(guān)鍵? 在循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)家族中,長短期記憶網(wǎng)絡(luò)(LSTM)憑借其解決長序列 ...
2025-07-11CDA 數(shù)據(jù)分析師報考條件詳解與準備指南? ? 在數(shù)據(jù)驅(qū)動決策的時代浪潮下,CDA 數(shù)據(jù)分析師認證愈發(fā)受到矚目,成為眾多有志投身數(shù) ...
2025-07-11數(shù)據(jù)透視表中兩列相乘合計的實用指南? 在數(shù)據(jù)分析的日常工作中,數(shù)據(jù)透視表憑借其強大的數(shù)據(jù)匯總和分析功能,成為了 Excel 用戶 ...
2025-07-11尊敬的考生: 您好! 我們誠摯通知您,CDA Level I和 Level II考試大綱將于 2025年7月25日 實施重大更新。 此次更新旨在確保認 ...
2025-07-10BI 大數(shù)據(jù)分析師:連接數(shù)據(jù)與業(yè)務(wù)的價值轉(zhuǎn)化者? ? 在大數(shù)據(jù)與商業(yè)智能(Business Intelligence,簡稱 BI)深度融合的時代,BI ...
2025-07-10SQL 在預(yù)測分析中的應(yīng)用:從數(shù)據(jù)查詢到趨勢預(yù)判? ? 在數(shù)據(jù)驅(qū)動決策的時代,預(yù)測分析作為挖掘數(shù)據(jù)潛在價值的核心手段,正被廣泛 ...
2025-07-10數(shù)據(jù)查詢結(jié)束后:分析師的收尾工作與價值深化? ? 在數(shù)據(jù)分析的全流程中,“query end”(查詢結(jié)束)并非工作的終點,而是將數(shù) ...
2025-07-10CDA 數(shù)據(jù)分析師考試:從報考到取證的全攻略? 在數(shù)字經(jīng)濟蓬勃發(fā)展的今天,數(shù)據(jù)分析師已成為各行業(yè)爭搶的核心人才,而 CDA(Certi ...
2025-07-09【CDA干貨】單樣本趨勢性檢驗:捕捉數(shù)據(jù)背后的時間軌跡? 在數(shù)據(jù)分析的版圖中,單樣本趨勢性檢驗如同一位耐心的偵探,專注于從單 ...
2025-07-09year_month數(shù)據(jù)類型:時間維度的精準切片? ? 在數(shù)據(jù)的世界里,時間是最不可或缺的維度之一,而year_month數(shù)據(jù)類型就像一把精準 ...
2025-07-09CDA 備考干貨:Python 在數(shù)據(jù)分析中的核心應(yīng)用與實戰(zhàn)技巧? ? 在 CDA 數(shù)據(jù)分析師認證考試中,Python 作為數(shù)據(jù)處理與分析的核心 ...
2025-07-08SPSS 中的 Mann-Kendall 檢驗:數(shù)據(jù)趨勢與突變分析的有力工具? ? ? 在數(shù)據(jù)分析的廣袤領(lǐng)域中,準確捕捉數(shù)據(jù)的趨勢變化以及識別 ...
2025-07-08備戰(zhàn) CDA 數(shù)據(jù)分析師考試:需要多久?如何規(guī)劃? CDA(Certified Data Analyst)數(shù)據(jù)分析師認證作為國內(nèi)權(quán)威的數(shù)據(jù)分析能力認證 ...
2025-07-08LSTM 輸出不確定的成因、影響與應(yīng)對策略? 長短期記憶網(wǎng)絡(luò)(LSTM)作為循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)的一種變體,憑借獨特的門控機制,在 ...
2025-07-07統(tǒng)計學方法在市場調(diào)研數(shù)據(jù)中的深度應(yīng)用? 市場調(diào)研是企業(yè)洞察市場動態(tài)、了解消費者需求的重要途徑,而統(tǒng)計學方法則是市場調(diào)研數(shù) ...
2025-07-07CDA數(shù)據(jù)分析師證書考試全攻略? 在數(shù)字化浪潮席卷全球的當下,數(shù)據(jù)已成為企業(yè)決策、行業(yè)發(fā)展的核心驅(qū)動力,數(shù)據(jù)分析師也因此成為 ...
2025-07-07剖析 CDA 數(shù)據(jù)分析師考試題型:解鎖高效備考與答題策略? CDA(Certified Data Analyst)數(shù)據(jù)分析師考試作為衡量數(shù)據(jù)專業(yè)能力的 ...
2025-07-04SQL Server 字符串截取轉(zhuǎn)日期:解鎖數(shù)據(jù)處理的關(guān)鍵技能? 在數(shù)據(jù)處理與分析工作中,數(shù)據(jù)格式的規(guī)范性是保證后續(xù)分析準確性的基礎(chǔ) ...
2025-07-04CDA 數(shù)據(jù)分析師視角:從數(shù)據(jù)迷霧中探尋商業(yè)真相? 在數(shù)字化浪潮席卷全球的今天,數(shù)據(jù)已成為企業(yè)決策的核心驅(qū)動力,CDA(Certifie ...
2025-07-04CDA 數(shù)據(jù)分析師:開啟數(shù)據(jù)職業(yè)發(fā)展新征程? ? 在數(shù)據(jù)成為核心生產(chǎn)要素的今天,數(shù)據(jù)分析師的職業(yè)價值愈發(fā)凸顯。CDA(Certified D ...
2025-07-03