SAS 中是否有与 R 函数表等效的函数表?
问题描述:
在 R 中,函数 table
使用交叉分类因子来构建列联表.是否有等效的 SAS PROC 可以重现此 R 函数的结果?
In R, the function table
uses cross-classifying factors to construct a contingency table. Is there an equivalent SAS PROC that can reproduce the result of this R function?
示例:
x <- data.frame(x=rep(1:2,times=5),y=rep(1:2,each=5))
# output: x
# x y
#1 1 1
#2 2 1
#3 1 1
#4 2 1
#5 1 1
#6 2 2
#7 1 2
#8 2 2
#9 1 2
#10 2 2
table(x)
# output: table(x)
# y
#x 1 2
#1 3 2
#2 2 3
答
是的,您想使用 Proc Freq.
Yes, You want to use Proc Freq.
Proc freq data=mydata;
table x; *gives table of single variable;
table x*y; *gives a crosstab;
by z; *will give multiple tables based on levels of z;
run;
3 个例子.变量 Diabetes_final 和 Diabetes,如果定义了任何糖尿病亚型,则第二个定义为 1.
3 examples. Variables Diabetes_final and Diabetes where the second one was defined be a 1 if any of the subtypes of diabetes were defined.
PROC FREQ DATA=ADS_R;
TABLE DIABETES_FINAL;
TABLE DIABETES;
TABLE DIABETES_FINAL*DIABETES;
TABLE DIABETES_FINAL*DIABETES/MISSPRINT LIST MISSING; ***SYNTAX FOR STRIPPED DOWN TABLE;
RUN;