2月 20, 2011

Posted by in 数据处理 | 8 条评论

SAS中保存统计分析步的结果至数据集中

在我们做完统计分析步(如proc reg等)后,有时想要将某些结果数据保存在数据集中,较为简单的常用方法有下面三种:使用proc步结果输出选项,使用output语句,使用ods output的方法。

下面以较为常用的proc reg步进行举例说明:

1.使用proc reg步结果输出选项

在proc reg ; 的options中可以选择outest= 选项来产生一个数据集,用于存储参数估计值、模型拟合的相关统计值等;同时还有edf、outseb、tableout、sse等选项(其他更多选项参见SAS help文档),可以将你想要的统计分析结果存储于outest= 生产的数据集中。

  • OUTEST= outputs a data set that contains parameter estimates and other model fit summary statistics
  • EDF outputs the number of regressors, the error degrees of freedom, and the model R2 to the OUTEST= data set
  • OUTSEB outputs standard errors of the parameter estimates to the OUTEST= data set
  • TABLEOUT outputs standard errors, confidence limits, and associated test statistics of the parameter estimates to the OUTEST= data set

例:

proc reg data=sashelp.class outest=result1 edf sse;
	model weight=height;
quit;

数据集work.result1如下:

2.使用proc reg步的output语句

在proc reg步中,output语句语法如下:
output <out=SAS-data-set >< keyword=names > < . . . keyword=names > ;

使用output语句可保存模型拟合后,模型诊断检验的一些数据结果。由于proc reg中可以有多个model语句,output对离它最近的一个model有效,并且,需至少定义一个keyword=names选项。keyword= 包括cookd=、h=、p=、r= 等选项(其他更多选项参见SAS help文档)。

  • COOKD=     Cook’s D influence statistic
  • H=     leverage
  • PREDICTED | P=     predicted values
  • RESIDUAL | R=     residuals, calculated as ACTUAL minus PREDICTED

例:

1
2
3
4
proc reg data=sashelp.class;
	model weight=height;
	output out=result2 p=p_value r=residuals;
quit;

数据集work.result2如下:

3.使用ods output的方法

使用ods output可以将统计分析的结果的任意部分存入数据集中。如对

1
2
3
proc reg data=sashelp.class;
	model weight=height;
quit;

在SAS的results窗口下,可以看到proc reg步结果列表

另外,使用ods trace可以在log窗口中查看输出结果,如下

1
2
3
4
5
ods trace on;
proc reg data=sashelp.class;
	model weight=height;
quit;
ods trace off;

如想保存Analysis of Variance的结果,其属性名为ANOVA,代码如下:

1
2
3
4
5
ods output anova=result3;
proc reg data=sashelp.class;
	model weight=height;
quit;
ods output close;

数据集work.result3如下:

参考文献
1.SAS STAT 9.2 User’s Guide (2d Edition)

  1. 学习了,最后一个ods output很强大

    [回复]

    hssnow 回复:

    呵呵,ods是很强大~

    [回复]

  2. 还有其他方法吗?据我所知,好像没有了,可能是我知道的有限。

    SAS 的proc reg很强大,也很完善。有很多其他统计proc语句没有options和output语句,但是ods output是一定可以用的,也是很常用的。

    还有方法1,方法2和方法3得到的结果不尽相同,取决于特定的proc句。

    ods再结合宏的应用,可以做很多重复性工作,用途很大。

    sxlion

    [回复]

    hssnow 回复:

    是否有其他方法小弟目前也不知道,呵呵。
    ods我还得再多学习学习。

    [回复]

    Admin 回复:

    haha,总结得挺好的,赞一个!

    [回复]

  3. 逐渐成长的SAS博客~再顶一个

    每次都来打酱油了…话说这里应该需要个表情的插件~

    [回复]

  4. 写的挺不错的!加油!话说我的博什么时候开始动呢,感觉没什么素材。

    [回复]

    hssnow 回复:

    呵呵,我也快1个月没更新了,时间上素材上都有限啊…

    [回复]

发表评论

返回顶部