Warren Repole

Don't Be a SAS® Dinosaur: Modernize Your SAS Programs
by Warren Repole

Summary Reports: Format Summary Statistics


Scenario:

You want to generate a report of summary statistics with each statistic formatted differently and having a custom column header.

The MEANS procedure can generate the statistics, but it has very limited features for customizing the report.


The old way: Create and Print a Summary Data Set

The original approach is to create an output data set from PROC MEANS, generating the report using PROC PRINT in order to customize the display through LABEL and FORMAT statements.

Download this program
proc means data=sashelp.class mean max nway;
  class Sex;
  var Height;
  output out=summary mean=Average max=Tallest;
  title1 "Default PROC MEANS report";
run;
proc print data=summary label;
  var Sex _freq_ Average Tallest;
  label _freq_="Students";
  format Average 5.2 Tallest 4.1;
  title1 "Formatting applied in PROC PRINT";
run;

SAS Log

17334  proc means data=sashelp.class mean max nway;
17335    class Sex;
17336    var Height;
17337    output out=summary mean=Average max=Tallest;
17338    title1 "Default PROC MEANS report";
17339  run;
 
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.SUMMARY has 2 observations and 5 variables.
 
17340  proc print data=summary label;
17341    var Sex _freq_ Average Tallest;
17342    label _freq_="Students";
17343    format Average 5.2 Tallest 4.1;
17344    title1 "Formatting applied in PROC PRINT";
17345  run;
 
NOTE: There were 2 observations read from the data set WORK.SUMMARY.
 

SAS Listing Output

Default PROC MEANS report
 
The MEANS Procedure
 
       Analysis Variable : Height
 
         N
Sex    Obs            Mean         Maximum
------------------------------------------
F        9      60.5888889      66.5000000
 
M       10      63.9100000      72.0000000
------------------------------------------
========================================================================================
Formatting applied in PROC PRINT
 
Obs    Sex    Students    Average    Tallest
 
 1      F         9        60.59      66.5
 2      M        10        63.91      72.0
stego

The new way: Create a Table Template for PROC MEANS
(available in SAS Version 8)

An alternate approach is to create a custom ODS table template to alter the default column headers and formats for PROC MEANS output.

Download this program
ods path work.temp(write) sashelp.tmplmst;
proc template;
  edit base.summary;
    edit NObs;
      header="Students";
    end;
    edit Mean;
      header="Average" format=5.2;
    end;
    edit Max;
      header="Tallest" format=4.1;
    end;
  end;
run;
proc means data=sashelp.class mean max;
  class Sex;
  var Height;
  title1 "Formatting applied in PROC MEANS";
run;
ods path sashelp.tmplmst;

SAS Log

17357  ods path work.temp(write) sashelp.tmplmst;
17358  proc template;
17359    edit base.summary;
17360      edit NObs;
17361        header="Students";
17362      end;
17363      edit Mean;
17364        header="Average" format=5.2;
17365      end;
17366      edit Max;
17367        header="Tallest" format=4.1;
17368      end;
17369    end;
NOTE: TABLE 'Base.Summary' has been saved to: WORK.TEMP
17370  run;
 
17371  proc means data=sashelp.class mean max;
17372    class Sex;
17373    var Height;
17374    title1 "Formatting applied in PROC MEANS";
17375  run;
 
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 
17376  ods path sashelp.tmplmst;

SAS Listing Output

Formatting applied in PROC MEANS
 
The MEANS Procedure
 
     Analysis Variable : Height
 
Sex    Students    Average    Tallest
-------------------------------------
F             9      60.59       66.5
 
M            10      63.91       72.0
-------------------------------------

Advantages of the alternate approach: Good

  • There is only one pass through the data.
  • No additional data sets are created.
  • The custom template can used in other applications if the definition is stored permanently.

Disadvantages of the alternate approach: Bad

  • The syntax and usage of PROC TEMPLATE may be unfamiliar and tends to be rather verbose. In particular, the manipulation of headers and spacing within the PROC MEANS output may not be straightforward.

Additional documentation for this technique can be found in SAS® 9.2 Output Delivery System User's Guide. Cary, NC: SAS Institute Inc.

Visit http://support.sas.com/documentation/onlinedoc/sas9doc.html for SAS 9 documentation.

The URL for this page is http://www.repole.com/dinosaur/meanstemplate.html

These techniques are mentioned in other SAS references and publications:


Back to SAS Dinosaur home page

Printable copy of this page (without sample output)

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries.

® indicates USA registration.