Send As SMS

Saturday, February 17, 2007

PROC REPORT with numeric calculated total title

This is very similar to PROC REPORT and PROC TABULATE with ratios and total titles, except that it uses a numeric variable for Sex and shows only PROC REPORT code.

options nocenter;

data test;
   do Sex = 1, 2, 2;
      do i = 1 to 847;
         Savings = round(ranuni(12345)*50, .01);
         Chgs = savings + round(ranuni(12345)*40, .01) +
(Sex=1)*Savings*.2;
         output;
      end;
   end;
   drop i;
   format chgs savings comma10.2;
run;

proc format;
   value sex
      1  = 'Male'
      2  = 'Female'
      ._ = 'Total'
      other = 'Unknown'
      ;
   picture tabpct
      0-100 = '009.9%'
      ;
run;

title 'Output from PROC REPORT';

proc report data=test 
     missing nowindows;

   column sex csex savings=nobs savings savings=meansavings chgs
chgs=meanchg SaveRate;

   define sex         / noprint group width=8;
   define csex        / computed 'Sex' format=sex.;
   define nobs        / n format=comma5.0 'N';
   define chgs        / sum;
   define meanchg     / mean 'Mean Chrgs';
   define savings     / sum;
   define meansavings / mean 'Mean Savings';
   define SaveRate    / computed format=percent7.1 'Savings Rate';

   compute saverate;
      saverate = savings.sum / chgs.sum;
   endcomp;

   compute csex;
      if _break_ = '_RBREAK_' then
         csex = ._;
      else
         csex = sex;
   endcomp;

   rbreak after / summarize;

run;

The output:

Output from PROC REPORT

SexNSavingsMean SavingsChgsMean ChrgsSavings Rate
Male 847 21,193.54 25.02 42,496.27 50.17 49.9%
Female 1,694 43,075.18 25.43 77,354.14 45.66 55.7%
Total 2,541 64,268.72 25.29119,850.41 47.17 53.6%

0 Comments:

Post a Comment

<< Home