用于计数单个类别或者多个类别的。统计中的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:
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 |
---|---|
|
|
( |
|
( |
|
|
|
( |
|
关于table更多的options可以根据连接进行了解。一般比较常用为数据集输出out = 以及列联表的可视化plots = ;
OUTPUT <OUT=SAS-data-set> output-options;
将结果以数据集形式保存,关于其中的统计信息可以参考(使用output语句除了要在该语句表明输出统计量同时在table生成过程也需要表明统计量 具体看 例二);
使用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;