Proc freq

PROC FREQ是SAS中用于创建一维到多维频数表的统计过程,它可以进行卡方检验、关联性分析等。常见应用场景包括计数分类变量,如班级男女学生人数或成绩等级分布。基本语法包括TABLES选项来定义列联表,配合OUTPUT选项将结果保存为数据集。使用BY变量可按特定顺序排序数据。了解更多详情可查阅SAS官方文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用于计数单个类别或者多个类别的。统计中的n*n列联表。HELP 文档:produces one-way to n-way frequency tables and reports frequency counts. PROC.FREQ can compute chi-square tests for one-way to n-way tables; for tests and measures of association and of agreement for two-way to n-way crosstabulation tables; risks and risk difference for 2×2 tables; trends tests;and Cochran-Mantel-Haenszel statistics. You can also create output data sets

常用到该proc情况:数据类型为定类变量。例如求A,B班级的男女同学人数,男女同学成绩中获得优良中差的个数。

syntax:

The following statements are available in the FREQ procedure:

PROC FREQ <options> ;

BY variables;

OUTPUT <OUT=SAS-data-set> output-options;

TABLES requests </ options> ;



SAS HELP Document:

:https://documentation.sas.com/docsetId=procstat&docsetTarget=procstat_freq_syntax.htm&docsetVersion=9.4&locale=en

PROC FREQ<options>详解


Option

Description

DATA=  *数据集的名称

Names the input data set

FORMCHAR= *输出table的格式设置(一般使用默认 水平方向用横线,纵向用竖线)

Specifies the outline and cell divider characters for crosstabulation tables

NLEVELS *table中的级别名字(一般不会使用到,默认为数据集中变量的取值)

Displays the number of levels for all TABLES variables

NOPRINT*是否将结果输出到result窗口

Suppresses all displayed output

ORDER= *按照何种排序方式为输出数据集进行排序

Specifies the order for reporting variable values

PAGE *一页只放一个表

Displays one table per page

COMPRESS*一页可以放多个表

Begins the next one-way table on the current page

*PAGE和COMPRESS只能出现其中一个

BY variables详解:数据集按照variables进行排序,事先要用sort PROC 

其中最为关键的为:

TABLES  variable:

下面表格为常用的表达形式:A*B为A与B的列联表:

TABLES Request

Equivalent to

A*(B C)

A*B   A*C

(A B)*(C D)

A*C   B*C   A*D   B*D

(A B C)*D

A*D   B*D   C*D

A – – C

A   B   C

(A – – C)*D

A*D   B*D   C*D

 

关于table更多的options可以根据连接进行了解。一般比较常用为数据集输出out = 以及列联表的可视化plots = ;

OUTPUT <OUT=SAS-data-set> output-options

将结果以数据集形式保存,关于其中的统计信息可以参考(使用output语句除了要在该语句表明输出统计量同时在table生成过程也需要表明统计量 具体看 例二);

https://documentation.sas.com/docsetId=procstat&docsetTarget=procstat_freq_syntax07.htm&docsetVersion=9.4&locale=en

使用output 语句 需要表明需要把哪些统计量写进数据集out = ,只想保留默认输出的统计量(计数以及相应的占比)可以在

table variable 后加/out= 既可。

举两个例子:

proc freq data = sashelp.class noprint;
tables sex*age / out = f;
run;

 

proc freq data = sashelp.class noprint;
 tables sex*age/ expected cellchi2 norow nocol chisq;
 output out=ChiSqData n nmiss pchi lrchi;
 run;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值