【问题标题】:Is there an equivalent to the R function table in SAS?SAS中是否有与R函数表等价的东西?
【发布时间】:2016-10-24 11:09:48
【问题描述】:

在R中,函数table使用交叉分类因子来构造列联表。是否有等效的 SAS PROC 可以重现此 R 函数的结果?

例子:

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

【问题讨论】:

    标签: r sas


    【解决方案1】:

    是的, 您想使用 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。

    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;
    

    【讨论】:

    • 如果有机会,能否提供一些示例输出?谢谢。
    • @JonathanLisic 根据要求。
    猜你喜欢
    • 2011-11-16
    • 2022-01-10
    • 2018-05-26
    • 2014-10-14
    • 2012-12-30
    • 2020-07-21
    • 1970-01-01
    • 2021-09-17
    • 2018-06-01
    相关资源
    最近更新 更多