Example 3.3. Displaying Descriptive Statistics in a Tabular Format

Goal

Compute descriptive statistics for several categories and arrange the statistics in a tabular format.

Report

                                        Exercise
 Program Results

        ------------------------------------------
----------------------------------------------
         |                  |                     
      Lipid Profile                           |
         |                 
 |---------------------
----------------------------------------------|
         |                  |          
 Cholesterol           |               HDL         
      |
         |                 
 |---------------------
------------+---------------------------------|
         |                  |   |     | Std |    
 |     |     |   |     | Std |     |     |     |
         |                  | N |Mean | Dev | P25
 | P50 | P75 | N |Mean | Dev | P25 | P50 | P75 |
         |------------------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |Gender  |Testing  |   |     |     |    
 |     |     |   |     |     |     |     |     |
         |--------|Period   |   |     |     |    
 |     |     |   |     |     |     |     |     |
         |Males   |---------|   |     |     |    
 |     |     |   |     |     |     |     |     |
         |        |Pre      | 15|220.6| 37.8|190
.0|219.0|250.0| 15| 43.3|  9.6| 32.0| 43.0| 51.0|
         |       
 |---------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |        |Post     | 15|202.1| 30.8|172
.0|205.0|216.0| 15| 43.9|  9.9| 33.0| 44.0| 52.0|
         |--------+---------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |Females |Pre      | 11|173.5| 21.2|158
.0|164.0|195.0| 11| 58.6|  8.9| 51.0| 60.0| 66.0|
         |       
 |---------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |        |Post     | 11|161.7| 18.3|149
.0|155.0|174.0| 11| 59.4|  7.7| 53.0| 60.0| 66.0|
         |--------+---------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |Both    |Pre      | 26|200.7| 39.3|164
.0|195.5|222.0| 26| 49.8| 11.9| 43.0| 51.0| 57.0|
         |Genders
 |---------+---+-----+-----+-----
+-----+-----+---+-----+-----+-----+-----+-----|
         |        |Post     | 26|185.0| 32.8|155
.0|180.0|207.0| 26| 50.4| 11.8| 44.0| 51.5| 60.0|
         -----------------------------------------
-----------------------------------------------

                         
 ------------------------------------------------------
                          |                  |    
      Lipid Profile          |
                          |                 
 |---------------------------------|
                          |                  |    
      Triglycerides          |
                          |                 
 |---------------------------------|
                          |                  |   |
     | Std |     |     |     |
                          |                  | N
 |Mean | Dev | P25 | P50 | P75 |
                         
 |------------------+---+-----+-----+-----+-----+-----|
                          |Gender  |Testing  |   |
     |     |     |     |     |
                          |--------|Period   |   |
     |     |     |     |     |
                          |Males   |---------|   |
     |     |     |     |     |
                          |        |Pre      |
 15|156.9| 81.9| 95.0|145.0|198.0|
                          |       
 |---------+---+-----+-----+-----+-----+-----|
                          |        |Post     |
 15|140.5| 71.3| 83.0|136.0|174.0|
                         
 |--------+---------+---+-----+-----+-----+-----+-----|
                          |Females |Pre      | 11|
 82.7| 36.2| 57.0| 65.0|114.0|
                          |       
 |---------+---+-----+-----+-----+-----+-----|
                          |        |Post     | 11|
 75.0| 30.9| 56.0| 69.0|101.0|
                         
 |--------+---------+---+-----+-----+-----+-----+-----|
                          |Both    |Pre      |
 26|125.5| 75.4| 65.0|108.0|150.0|
                          |Genders
 |---------+---+-----+-----+-----+-----+-----|
                          |        |Post     |
 26|112.8| 65.7| 61.0| 95.5|141.0|
                         
 ------------------------------------------------------


Example Features

Data SetLIPIDS
Featured StepPROC TABULATE
Featured Step Statements and OptionsCLASS statement: DESCENDING option
Formatting FeaturesTABLE statement: NOCONTINUED option TABLE statement: CONDENSE and RTS= options when sending output to the LISTING destination
Related TechniquePROC REPORT, DEFINE statement: GROUP option
A Closer LookComparing PROC TABULATE and PROC REPORT for Generating the Report in this Example
ODS Enhanced Version of This ExampleExample 6.8 and 6.9
Other Examples That Use This Data SetExamples 2.7, 6.4, 6.8, and 6.9

Example Overview

Presenting descriptive statistics in a tabular format can help you quickly review your data set. The report in this example presents several descriptive statistics for the blood tests in the LIPIDS data set. It groups the observations in the data set by gender and testing period, and it also computes the statistics with genders combined.

Each observation in the LIPIDS data set corresponds to the lipid measurements for one participant during one of the two testing periods.

See the related technique in Example 3.1 for another example of displaying statistics in a tabular format.

Program

Define a format for one of the CLASS variables in the PROC TABULATE step.
proc format;
  value $gender 'M'='Males'
                'F'='Females';
run;

proc tabulate data=lipids;
  title 'Exercise Program Results';

To display males before females and “Pre” program results before “Post” program results, specify that the categories of the two class variables, GENDER and TIME, should be listed in descending order.
  class gender testperiod / descending;

Specify the analysis variables.
  var chol hdl tri;

  table

Define the arrangement of the class variables in the row dimension.
         (gender='Gender'

Compute statistics for both genders combined.
         all='Both Genders')*

Nest the categories of TESTPERIOD beneath the categories of GENDER and the summary variable ALL.
         testperiod='Testing Period',

Place a heading over the following three analysis variables.
         all='Lipid Profile'*

Nest the three analysis variables beneath the heading specified in the preceding ALL= specification.
         (chol='Cholesterol' hdl='HDL'
         tri='Triglycerides')*

Specify the statistics that should be computed for each analysis variable, and specify the display format of the statistics.
         (n*f=3. (mean std='Std Dev' p25 p50
          p75)*f=5.1) /

Place as many logical pages as possible on one physical page when sending output to the LISTING destination.
          condense

Omit the default printing of the “(Continued)” message.
          nocontinued

When sending output to the LISTING destination, specify the space allocated to row titles.
          rts=20;
  format  gender $gender.;
run;


Related Technique

PROC REPORT can also produce a tabular report of descriptive statistics, as shown in Figure 3.3. Here are some differences in the output in Figure 3.3 compared to the output from the main example:

The summary by time period is omitted.
Cholesterol and HDL results are on one page.
Triglycerides results are on the second page.

Figure 3.3. Output from PROC REPORT
                                      Exercise Program Results

------------------------------------------------------------------------------------------
--------
|                  -------------Cholesterol-------------- 
 -----------------HDL-------------------|
|         Testing                Std                                     Std              
        |
|Gender   Period     N   Mean    Dev    P25    P50    P75    N   Mean    Dev    P25    P50
     P75|
|-----------------------------------------------------------------------------------------
--------|
|Males  | Pre    |  15| 220.6|  37.8| 190.0| 219.0| 250.0|  15|  43.3|    9.6|  32.0|  43
.0|  51.0|
|       |--------+----+------+------+------+------+------+----+------+-------+------+-----
-+------|
|       | Post   |  15| 202.1|  30.8| 172.0| 205.0| 216.0|  15|  43.9|    9.9|  33.0|  44
.0|  52.0|
|-------+--------+----+------+------+------+------+------+----+------+-------+------+-----
-+------|
|Females| Pre    |  11| 173.5|  21.2| 158.0| 164.0| 195.0|  11|  58.6|    8.9|  51.0|  60
.0|  66.0|
|       |--------+----+------+------+------+------+------+----+------+-------+------+-----
-+------|
|       | Post   |  11| 161.7|  18.3| 149.0| 155.0| 174.0|  11|  59.4|    7.7|  53.0|  60
.0|  66.0|
------------------------------------------------------------------------------------------
--------

---------------------------------------------page
 break-----------------------------------------------

                                      Exercise Program Results

                    ----------------------------------------------------------
                    |                  ------------Triglycerides--------------|
                    |         Testing                Std                      |
                    |Gender   Period     N   Mean    Dev    P25    P50     P75|
                    |---------------------------------------------------------|
                    |Males  | Pre     |  15| 156.9|  81.9|  95.0| 145.0| 198.0|
                    |       |---------+----+------+------+------+------+------|
                    |       | Post    |  15| 140.5|  71.3|  83.0| 136.0| 174.0|
                    |-------+---------+----+------+------+------+------+------|
                    |Females| Pre     |  11|  82.7|  36.2|  57.0|  65.0| 114.0|
                    |       |---------+----+------+------+------+------+------|
                    |       | Post    |  11|  75.0|  30.9|  56.0|  69.0| 101.0|
                    ----------------------------------------------------------

The following PROC REPORT step produces the report shown in Figure 3.3.

 
proc format;

Specify the same format as was used in the main example to label the values of GENDER.
  value $gender 'M'='Males'
                'F'='Females';
run;

proc report data=lipids nowindows box;
  title 'Exercise Program Results';

Specify the columns in the report.
  column gender testperiod

List within parentheses the statistics that are to be computed on each analysis variable. Nest the set of statistics beneath the heading for the analysis variable.
         chol,(n mean std p25 p50 p75)
         hdl,(n mean std p25 p50 p75)
         tri,(n mean std p25 p50 p75);

Group the data by gender and time of testing. Arrange the values of the two grouping variables in descending order so that data for males prints before females, and data for the “Pre” testing period prints before the “Post” testing period.
  define gender / group format=$gender. left id
                  descending 'Gender';
  define testperiod / group left id descending
                     'Testing Period' width=7;

Specify the analysis variables. When sending output to the LISTING destination, pad the heading for each analysis variable with dashes.
  define chol / '-Cholesterol-';
  define hdl / '-HDL-';
  define tri / '-Triglycerides-';

Specify the attributes of the statistics.
  define n / format=4. 'N';
  define mean / format=5.1 'Mean';
  define std / format=5.1 'Std Dev';
  define p25 / format=5.1 'P25';
  define p50 / format=5.1 'P50';
  define p75 / format=5.1 'P75';
run;


A Closer Look

Comparing PROC TABULATE and PROC REPORT for Generating the Report in this Example

Both PROC TABULATE and PROC REPORT can summarize data by categories. Each procedure has its strengths and weaknesses.

Strengths of PROC TABULATE

In this example, you might prefer PROC TABULATE for these reasons:

Ability to summarize the classification variables in specific ways within one step. PROC TABULATE provides the flexibility to construct summarization requests within the TABLE statement. The PROC TABULATE step analyzes the data by gender and overall for each testing period, whereas the PROC REPORT step did not. For PROC REPORT to produce the overall summarization for each testing period and have it included as the last two rows of the report requires COMPUTE blocks and programming statements. Alternatively, you could issue two PROC REPORT steps. The first would be the same as the program in the related technique. The second step would drop GENDER as a group variable.
Ability to condense multiple logical pages onto fewer physical pages when sending the report to the LISTING destination. Both reports above were sent to the LISTING destination. The CONDENSE option on the PROC TABULATE TABLE statement caused the report to be displayed on one page. If this option was omitted, the triglyceride results and the overall results would be on a second page. PROC REPORT does not have an option similar to CONDENSE. Therefore, it sends the triglycerides results to a second page. (When you send the report to a nonlisting destination, such as RTF, the PROC REPORT report is placed on one page.)

Strengths of PROC REPORT

You might prefer PROC REPORT for these reasons:

Ability to add text to the report and add text that is based on the results in the report. With PROC REPORT COMPUTE blocks and programming statements, you can add information to your report and control its placement. The information you add can be derived from the results obtained in the report step.

PROC TABULATE does not have statements or options that give you as much control over content and placement of text as PROC REPORT. The BOX= option on the TABLE statement enables you to add text to the upper left box of a PROC TABULATE table. You can add headings to the report as demonstrated by the placement of the text “Lipid Profile” above the statistics for the three analysis variables.

Both PROC REPORT and PROC TABULATE can use ODS features to add text in specific locations of a report. For further information, see SAS 9.1 Output Delivery System: User’s Guide. For updates to the reference and new developments in ODS, see online resources at support.sas.com/v9doc.
Ability to compute new columns. COMPUTE blocks and programming statements enable you to create new columns in a report produced by PROC REPORT. PROC TABULATE does not have this functionality. You would have to add these variables to your input data set prior to the PROC TABULATE step.

Where to Go from Here

PROC REPORT reference, usage information, and additional examples. See “The REPORT Procedure” in the “Procedures” section of Base SAS 9.1 Procedures Guide.

PROC TABULATE reference, usage information, and additional examples. See “The TABULATE Procedure” in the “Procedures” section of Base SAS 9.1 Procedures Guide.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.41