在PROC报告中计算'跨越'变量

时间:2013-09-13 09:58:12

标签: sas

我正在尝试使用别名为PROC REPORT中的同一变量创建多个统计信息。这是我之前发布的一篇文章的详细说明,但我将其作为一个单独的问题发布,因为样本数据已经改变,问题涉及更多。

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

PROC PRINT; RUN;

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

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

上面列表提供的输出是我想要的,虽然我最终会添加一些更多的计算字段,所以我想用PROC REPORT来做这个。

PROC REPORT DATA=ranksout1 NOWINDOWS;
    COLUMN stakerank winnerrank, (N stake=stakemean discountedstake);
    DEFINE stakerank / GROUP '' ORDER=INTERNAL;
    DEFINE winnerrank / ACROSS '' ORDER=INTERNAL;
    DEFINE stake / ANALYSIS N 'Count';
    DEFINE stakemean / ANALYSIS MEAN 'Mean' format=8.2;
    DEFINE discountedstake / computed format=8.2;
    COMPUTE discountedstake;
        discountedstake = stakemean * 0.9;
    ENDCOMP;
RUN;

当我开始使用逗号和括号对变量'ACROSS'进行分组时,我似乎根本无法插入计算变量。它是有效的,如果我只使用GROUP一次,但如果我介绍winsrank分组,它不起作用。我收到错误告诉我“缺失值已经生成”,并且'利益已经未初始化'。

会感激任何提示。感谢。

1 个答案:

答案 0 :(得分:2)

也许这会有所帮助: 在详细数据的SAS视图中准备计算变量:

data ranks_view / view=ranks_view;
set ranksout1;
    discountedstake = stake * 0.9;
run;

PROC REPORT DATA=ranks_view NOWINDOWS;
    COLUMN stakerank winnerrank, (N stake=stakemean discountedstake);
    DEFINE stakerank / GROUP '' ORDER=INTERNAL;
    DEFINE winnerrank / ACROSS '' ORDER=INTERNAL;
    DEFINE stake / ANALYSIS N 'Count';
    DEFINE stakemean / ANALYSIS MEAN 'Mean' format=8.2;
    DEFINE discountedstake / ANALYSIS MEAN format=8.2;
RUN;

DEFINE discountedstake / ANALYSIS MEAN format=8.2;中 - MEAN表示结果是平均折扣金额。