1
votes

I'm trying to use a alias to create multiple statistics for the same variable in PROC REPORT. This is an elaboration on a previous post I put up, but am posting it as a separate question because the sample data has changed and the question is a bit more involved.

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;

The output provided by tabulate above is what I want, although I will ultimately be adding some more calculated fields so would like to do this with 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;

When I start grouping the variables 'ACROSS' using commas and brackets, I can't seem to insert a calculated variable at all. It works if I only GROUP once on stakerank, but if I introduce the winnerrank grouping, it doesn't work. I get errors telling me that 'missing values were generated', and that 'stakemean is uninitialized'.

Would appreciate any tips at all. Thanks.

1

1 Answers

2
votes

Maybe this helps: preparing calculated variable in SAS view on detail data:

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 says the result is average of discountedstake.