Calculate Skewness in PROC REPORT

流过昼夜 提交于 2020-01-05 08:40:56

问题


I have the following sample data with I'm creating a crosstab for:

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;

I want to replicate what I'm doing in PROC TABULATE in PROC REPORT as I need to add p-values for a Difference in Means test and a few other things. However, it seems that Skewness is not a built-in function in Proc Report. How can I calculate this?

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;

Thanks for any help at all on this


回答1:


It can be done as follows.

Adding an extra intermediate variable to the rankouts1 table:

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;

Why didn't they just add Skewness to the list of statistics that are allowed in a PROC REPORT?



来源:https://stackoverflow.com/questions/18766635/calculate-skewness-in-proc-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!