0

我使用 Proc freq 来计算因变量(对数薪水)和自变量(crhits、crhome 等)之间的 Somers' D

有没有办法在一个 proc freq 语句中获得所有结果?

我目前使用的代码是

    DATA baseball;
        SET sashelp.baseball;
    RUN;

    PROC SORT 
        DATA = baseball; 
        BY team; 
    RUN;

    PROC FREQ 
        DATA = baseball
        ;
        TABLES logsalary * crhits
        / 
        MEASURES;
        OUTPUT OUT = somersd
            (KEEP = team N _SMDCR_
            RENAME = (_SMDCR_ = somers_d
                       N = num_in_group))
        MEASURES;
        BY team;
    RUN;

我希望在一个表中为每个变量 crhits、crhome 等获取输出“somersd”,并在一个过程中完成所有这些,这可能吗?

4

1 回答 1

1

为什么不直接转置数据,使自变量成为新的 BY 组?

proc transpose data=sashelp.baseball out=tall name=stat;
  by name team logsalary notsorted;
  var crhits crhome;
run;
proc sort;
  by team stat;
run;

ods exclude all;
PROC FREQ DATA = tall ;
  BY team stat;
  TABLES logsalary * col1 / MEASURES;
  output measures out=measures
    (KEEP = team stat N _SMDCR_
     RENAME = (_SMDCR_ = somers_d N = num_in_group)
    ) 
  ;
RUN;
ods exclude none;
于 2019-05-23T14:57:37.973 回答