使用SAS.report替代print、means、sort以及tabulate

        正如《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代码都是行之有效的,希望大家批评指正的同时给出宝贵意见。


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等雪的人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值