sasproc-report

PROC Report, multiple columns with same statistic


I'm using PROC REPORT to generate a report of weighted sums. There are 2 columns that need to be summarized, both with the MEAN statistic. On top of that, I want to output the total weight.

I have 2 issues.

  1. I cannot seem to get the title on each sum to reflect the variable being summed.

  2. I need a different format for each column.

Here is some sample data:

data test;
format lev1-lev3 $3. weight percent10.2 duration 6.2 convexity 6.4;
informat weight percent10.2 duration  6.2 convexity 6.4;
input lev1  lev2    lev3    weight  duration convexity;
datalines;
A   C   H   16.11%  3.21 0.6182
A   C   I   3.83%   9.06 1.2244
A   D   J   7.67%   2.21 3.4010
A   D   K   16.90%  3.98 0.0303
B   E   L   2.68%   1.88 1.9515
B   E   M   16.68%  4.36 3.1851
B   F   N   20.79%  2.64 0.1145
B   F   O   15.34%  5.55 2.4408
;
run;

I've tried a number of ways to define things in PROC REPORT. Here is one of many:

proc report data=test nowd out=report;
column lev1 lev2 lev3 duration,(SUMWGT MEAN) convexity,(Mean);
weight weight;
define lev1 / group;
define lev2 / group;
define lev3 / group;
define duration / 'Duration' ;
define sumwgt / 'Weight' format=percent10.2;
define mean / '' format=6.2;
define convexity / 'Convexity';
*define mean / 'Convexity' format=6.4;

break before lev1 / summarize ;
break before lev2 / summarize ;
rbreak before / summarize;
run;

My ultimate goal would be something like:

Lev1 Lev2 Lev3 Weight    Duration Convextiy
               100.00%   3.88     1.3943
A               44.51%   3.83     0.9267
...

I've also played with PROC TABULATE but I am less of a fan of the tables it presents.

Example TABULATE mess:

PROC TABULATE DATA=WORK.test;   
    VAR duration convexity;
    CLASS LEV1 /    ORDER=UNFORMATTED MISSING;
    CLASS LEV2 /    ORDER=UNFORMATTED MISSING;
    CLASS LEV3 /    ORDER=UNFORMATTED MISSING;

TABLE 
/* Row Dimension */
ALL={LABEL="+"}
LEV1*(
  ALL={LABEL="+"}
  LEV2*(
    ALL={LABEL="+"}
    LEV3 ) )
,

/* Column Dimension */
duration={LABEL="Weight"}*SumWgt={LABEL=""}*f=percent10.2 
duration={LABEL="Duration"}*Mean={LABEL=""}*f=6.2   
convexity={LABEL="Convexity"}*Mean={LABEL=""}*f=6.4;

WEIGHT weight;

RUN;

Solution

  • I think you'll have challenges getting exactly what you want from PROC REPORT. Maybe Cynthia@SAS could figure it out, I don't know, but getting the row headers right in particular will be extremely challenging.

    I would suggest pre-processing the means (using PROC MEANS or similar) and then REPORTing that result. Very easy to do.

    This may be close to what you want, for example:

    proc means data=test;
    class lev1 lev2 lev3;
    var duration convexity;
    weight weight;
    types () lev1 lev1*lev2 lev1*lev2*lev3;
    output out=test_out
      sumwgt(duration)=sumwgt mean(duration)= mean(convexity)=;
    run;
    
    
    proc report data=test_out;
     columns lev1-lev3 sumwgt duration convexity;
     define lev1/order missing;
     define lev2/order missing;
     define lev3/order missing;
     define sumwgt/display format=percent9.2;
     define duration/display format=6.2;
     define convexity/display format=6.4;
    run;