计算PROC报告中的偏差

时间:2013-09-12 14:12:06

标签: sas

我有以下示例数据,我正在创建一个交叉表:

data have1;
   input username $  betdate : datetime. stake winnings;
   dateOnly = datepart(betdate) ;
   format betdate DATETIME.;
   format dateOnly ddmmyy8.;
   datalines; 
    player1 12NOV2008:12:04:01 90 -90 
    player1 04NOV2008:09:03:44 100 40 
    player2 07NOV2008:14:03:33 120 -120 
    player1 05NOV2008:09:00:00 50 15 
    player1 05NOV2008:09:05:00 30 5 
    player1 05NOV2008:09:00:05 20 10 
    player2 09NOV2008:10:05:10 10 -10 
    player2 15NOV2008:15:05:33 35 -35 
    player1 15NOV2008:15:05:33 35 15 
    player1 15NOV2008:15:05:33 35 15 
run;
PROC PRINT; RUN;

Proc rank data=have1 ties=mean out=ranksout groups=2;
     var    stake;
     ranks  stakeRank;
run;

PROC TABULATE DATA=ranksout NOSEPS;
    VAR stake;
    class stakerank;
    TABLE stakerank, stake*N;
        TABLE stakerank, stake*(N Mean Skewness);
RUN;

我想在PROC报告中复制我在PROC TABULATE中所做的事情,因为我需要为Means in Means测试和其他一些东西添加p值。但是,似乎Skewness不是Proc Report中的内置函数。我该怎么计算呢?

PROC REPORT DATA=ranksout NOWINDOWS;
  COLUMN stakerank stake, (n mean);
  DEFINE stakerank / GROUP id 'Rank for Variable Stake' ORDER=INTERNAL;
  DEFINE stake / ANALYSIS '';
  define n/format=8. ;
RUN;

感谢您对此提供任何帮助

1 个答案:

答案 0 :(得分:0)

可以按照以下方式完成。

将额外的中间变量添加到rankouts1表中:

proc sql;
    create table withCubedDeviationsas
    select *,
    ((stake - (select avg(stake) from ranksout1 where stakeRank = main.stakeRank and  winnerRank = main.winnerRank))/(select std(stake) from ranksout1 where stakeRank = main.stakeRank and  winnerRank = main.winnerRank)) **3 format=8.2 as cubeddeviations
    from ranksout1 main;    
quit;

PROC REPORT DATA=withCubedDeviationsNOWINDOWS out=report;
    COLUMN stakerank winnerrank, ( N stake=avg cubeddeviations skewness);
    DEFINE stakerank / GROUP  ORDER=INTERNAL '';
    DEFINE winnerrank / ACROSS  ORDER=INTERNAL '';
    DEFINE cubeddeviations / analysis 'SumCD' noprint;
    DEFINE N / 'Bettors';
    DEFINE avg / analysis mean 'Avg' format=8.2;
    DEFINE skewness / computed format=8.2 'Skewness';
    COMPUTE skewness;
        _C5_ =  _C4_ * (_C2_ / ((_C2_ -1) * (_C2_ - 2)));
        _C9_ =  _C8_ * (_C6_ / ((_C6_ -1) * (_C6_ - 2)));
    ENDCOMP;
RUN;

为什么他们不将Skewness添加到PROC报告中允许的统计列表中?