1

我正在尝试使用别名为 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”进行分组时,我似乎根本无法插入计算变量。如果我只在stakerank 上分组一次,它就可以工作,但如果我引入winnerrank 分组,它就行不通。我收到错误消息,告诉我“生成了缺失值”,并且“stakemean 未初始化”。

将不胜感激任何提示。谢谢。

4

1 回答 1

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;

In DEFINE discountedstake / ANALYSIS MEAN format=8.2;- MEAN 表示结果是折现股权的平均值。

于 2013-09-13T10:36:10.630 回答