正如《the little sas book》所说,在sas中Report 包含 print、means 和 tabulate、sort 的所有功能,基本形式为:
PROC report options;/*options常用的有nowindows headline headskip missing*/
column variable-list;
define variable-list/options '';/*options常用的有group across order display*/
break location varivale/options;/*location为before或after,options常用的有ol skip summarize*/
rbreak location/options;/*location与options选项等同于break*/
run;
其中Column 语句告诉 SAS 哪些变量该包括并以何种顺序,如果遗漏语句 column,SAS 默认在数据集中包括所有变量,如果遗漏选项 nowINDOWS,SAS 默认 启用交互 report 窗口。可以在report后增加选项 headline 和 headskip,为输出后报告预留出标题和副标题的空位。
接下来我们将report与print、means 和 tabulate、sort进行对比 ,你会发现这是一个既简单又好用、还特别强大的命令。
1.替代print
假设学校随机对三个班级发放糖果,牛奶糖(candy1)以及咖啡糖(candy2),接下来对不同班级男(m)女生(f)所获得的糖果数进行调查统计,数据输入如下:
分别使用report以及print对数据进行分析,代码输入以及结果展示如下(由于report命令中,默认对数值变量进行加和处理,因此我们适用define variable-list/display对变量candy1以及candy2中每个变量值创建一行):
proc print data=candy noobs;
var candy1 candy2;
title 'the result of print';
run;
proc report data=candy missing headline;
column candy1 candy2;
define candy1/display;
define candy2/display;
title 'the result of report';
run;
2.report和sort
分别使用report以及sort对数据进行分析,代码输入以及结果展示如下:
/*sort的结果代码*/
proc sort data=candy out=candys;
by candy1 descending candy2;
run;
proc print data=candys noobs;
var candy1 candy2;
title 'the result of sort';
run;
/*report的结果代码*/
proc report data=candy missing nowindows;
column candy1 candy2;
define candy2/order descending;
define candy1/order ;
title 'the result of report';
run;
3.report与tabulate、means
由于means中的功能在report命令中基本都体现在制作报表的过程中,因此我们将在与tabulate对比时加入一些means可能包含的功能。下面我们将代码以及输出结果进行展示(我们使用mean平均值进行演示,不过由于没有重复值,因此结果与原数据并无区别,至于means中其他功能如pctn、max之类也是大同小异):
/*tabulate代码*/
proc tabulate data=candy missing;
class class sex;
var candy1 candy2;
table class='',sex=''*(candy1*format=best2. candy2*format=best2.)*mean='';
title 'the result of tabulate';
run;
/*report代码*/
proc report data=candy missing nowindows;
column class sex, (candy1 candy2),mean;
define class /group '';
define sex/across '';
define mean/'';
title 'the result of report';
run;
4.其他
report语句中还有break、rbreak、compute的其他用法,由于不是本文立意所在,不在赘述。
另外,本人水平有限,对于数据处理以及sas应用难免存在一定不足,但上述sas代码都是行之有效的,希望大家批评指正的同时给出宝贵意见。