Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Using the Output Delivery System

Example 15.10: Using the TEMPLATE Procedure to Customize Output

You can use the TEMPLATE procedure to modify the appearance of your displayed ODS tables. The following example, similar to that given in Olinger and Tobias (1998), creates output data sets using the ODS OUTPUT statement, modifies a template using PROC TEMPLATE, and displays the output data sets using the modified template.

The data set comes from a preclinical drug experiment (Cole and Grizzle 1966). In order to study the effect of two different drugs on histamine levels in the blood, researchers administer the drugs to 13 animals, and the levels of histamine in the animals' blood is measured after 0, 1, 3, and 5 minutes. The response variable is the logarithm of the histamine level. The following statements create a SAS data set named Histamine that contains the experimental data.

   title1 "Histamine Study";
   data Histamine;
      input Drug $12. Depleted $ hist0 hist1 hist3 hist5;
      logHist0 = log(hist0); logHist1 = log(Hist1);
      logHist3 = log(hist3); logHist5 = log(Hist5);
      datalines;
   Morphine      N  .04  .20  .10  .08
   Morphine      N  .02  .06  .02  .02
   Morphine      N  .07 1.40  .48  .24
   Morphine      N  .17  .57  .35  .24
   Morphine      Y  .10  .09  .13  .14
   Morphine      Y  .07  .07  .06  .07
   Morphine      Y  .05  .07  .06  .07
   Trimethaphan  N  .03  .62  .31  .22
   Trimethaphan  N  .03 1.05  .73  .60
   Trimethaphan  N  .07  .83 1.07  .80
   Trimethaphan  N  .09 3.13 2.06 1.23
   Trimethaphan  Y  .10  .09  .09  .08
   Trimethaphan  Y  .08  .09  .09  .10
   Trimethaphan  Y  .13  .10  .12  .12
   Trimethaphan  Y  .06  .05  .05  .05
   ;

In the analysis that follows, the GLM procedure is invoked to perform a repeated measures analysis, naming the drug and depletion status as between-subject factors in the MODEL statement and naming post-administration measurement time as the within-subject factor (for more information on this study and its analysis, see Example 7 in Chapter 30, "The GLM Procedure").

The following ODS statement requests that two ODS tables be written to SAS data sets called HistWithin and HistBetween. The SAS listing is closed so that no output is displayed. The GLM procedure is invoked and the model is fit.

   ods output MultStat                     = HistWithin
              BetweenSubjects.ModelANOVA   = HistBetween;

   ods listing close;

   proc glm data=Histamine;
      class Drug Depleted;
      model LogHist0--LogHist5 = Drug Depleted Drug*Depleted / nouni;
      repeated Time 4 (0 1 3 5) polynomial / summary printe;
   run;
   quit;

All of the multivariate test results appear in the HistWithin data set. This is because all multivariate test tables are named "MultStat," although they occur in different directories in the output directory hierarchy.

Note that, even though there are also other tables named "ModelANOVA," the preceding ODS OUTPUT statement ensures that only the between-subject ANOVA appears in the HistBetween data set. The specific table is selected because of the additional specification of the partial path ("BetweenSubjects") in which it occurs. For more information on names and qualified path names, see the discussion in the section "Using the Output Delivery System".

In the following statements, a new data set, temp1, is created to contain the two data sets output in the preceding GLM run. They are displayed with no further processing.

   ods listing;
   title2 'Listing of Raw Data Sets';
   data temp1;
      set HistBetween HistWithin;
   run;
   proc print;
   run;

Output 15.10.1: Listing of the Raw Data Sets: Histamine Study

                                                    Histamine Study
                                                Listing of Raw Data Sets

                            Hypothesis
  Obs       Dependent          Type       Source               DF              SS              MS     FValue     ProbF

    1    BetweenSubjects            3     Drug                  1      5.99336243      5.99336243       2.71    0.1281
    2    BetweenSubjects            3     Depleted              1     15.44840703     15.44840703       6.98    0.0229
    3    BetweenSubjects            3     Drug*Depleted         1      4.69087508      4.69087508       2.12    0.1734
    4    BetweenSubjects            3     Error                11     24.34683348      2.21334850        _       _    
    5                               .                           .       .               .              24.03    0.0001
    6                               .                           .       .               .              24.03    0.0001
    7                               .                           .       .               .              24.03    0.0001
    8                               .                           .       .               .              24.03    0.0001
    9                               .                           .       .               .               5.78    0.0175
   10                               .                           .       .               .               5.78    0.0175
   11                               .                           .       .               .               5.78    0.0175
   12                               .                           .       .               .               5.78    0.0175
   13                               .                           .       .               .              21.31    0.0002
   14                               .                           .       .               .              21.31    0.0002
   15                               .                           .       .               .              21.31    0.0002
   16                               .                           .       .               .              21.31    0.0002
   17                               .                           .       .               .              12.48    0.0015
   18                               .                           .       .               .              12.48    0.0015
   19                               .                           .       .               .              12.48    0.0015
   20                               .                           .       .               .              12.48    0.0015

 
  Obs    Hypothesis                  Error          Statistic                        Value     NumDF     DenDF

    1                                                                            .                 .         .
    2                                                                            .                 .         .
    3                                                                            .                 .         .
    4                                                                            .                 .         .
    5    Time                  Error SSCP Matrix    Wilks' Lambda               0.11097706         3         9
    6    Time                  Error SSCP Matrix    Pillai's Trace              0.88902294         3         9
    7    Time                  Error SSCP Matrix    Hotelling-Lawley Trace      8.01087137         3         9
    8    Time                  Error SSCP Matrix    Roy's Greatest Root         8.01087137         3         9
    9    Time_Drug             Error SSCP Matrix    Wilks' Lambda               0.34155984         3         9
   10    Time_Drug             Error SSCP Matrix    Pillai's Trace              0.65844016         3         9
   11    Time_Drug             Error SSCP Matrix    Hotelling-Lawley Trace      1.92774470         3         9
   12    Time_Drug             Error SSCP Matrix    Roy's Greatest Root         1.92774470         3         9
   13    Time_Depleted         Error SSCP Matrix    Wilks' Lambda               0.12339988         3         9
   14    Time_Depleted         Error SSCP Matrix    Pillai's Trace              0.87660012         3         9
   15    Time_Depleted         Error SSCP Matrix    Hotelling-Lawley Trace      7.10373567         3         9
   16    Time_Depleted         Error SSCP Matrix    Roy's Greatest Root         7.10373567         3         9
   17    Time_Drug_Depleted    Error SSCP Matrix    Wilks' Lambda               0.19383010         3         9
   18    Time_Drug_Depleted    Error SSCP Matrix    Pillai's Trace              0.80616990         3         9
   19    Time_Drug_Depleted    Error SSCP Matrix    Hotelling-Lawley Trace      4.15915732         3         9
   20    Time_Drug_Depleted    Error SSCP Matrix    Roy's Greatest Root         4.15915732         3         9

In order to reduce the amount of information displayed in Output 15.10.1, this example creates the following data set, HistTests. Only the observations from the raw data sets that are needed for interpretation are included. The variable Hypothesis in the HistWithin data set is renamed to Source, and the NumDF variable is renamed DF. The renamed variables correspond to the variable names found in the HistBetween data set.

   data HistTests;
      set HistBetween(where =(Source    ^= "Error"))
          HistWithin (rename=(Hypothesis =  Source NumDF=DF)
                      where =(Statistic  = "Hotelling-Lawley Trace"));
   run;
   proc print ;
   title2 'Listing of Selections from the Raw Data Sets';
   run;

Output 15.10.2: Listing of Selections from the Raw Data Sets: Histamine Study

                                      Listing of Selections from the Raw Data Sets

                                    Hypothesis
          Obs       Dependent          Type       Source                    DF              SS              MS

           1     BetweenSubjects            3     Drug                       1      5.99336243      5.99336243
           2     BetweenSubjects            3     Depleted                   1     15.44840703     15.44840703
           3     BetweenSubjects            3     Drug*Depleted              1      4.69087508      4.69087508
           4                                .     Time                       3       .               .        
           5                                .     Time_Drug                  3       .               .        
           6                                .     Time_Depleted              3       .               .        
           7                                .     Time_Drug_Depleted         3       .               .        

 
          Obs     FValue     ProbF          Error                Statistic                  Value     DenDF

           1        2.71    0.1281                                                      .                 .
           2        6.98    0.0229                                                      .                 .
           3        2.12    0.1734                                                      .                 .
           4       24.03    0.0001    Error SSCP Matrix    Hotelling-Lawley Trace      8.01087137         9
           5        5.78    0.0175    Error SSCP Matrix    Hotelling-Lawley Trace      1.92774470         9
           6       21.31    0.0002    Error SSCP Matrix    Hotelling-Lawley Trace      7.10373567         9
           7       12.48    0.0015    Error SSCP Matrix    Hotelling-Lawley Trace      4.15915732         9



The amount of information contained in the HistTests is appropriate for interpreting the analysis (Output 15.10.2). However, you can further modify the presentation of the data by applying a template to this combined test data. A template specifies how data should be displayed. The output from previous ODS TRACE ON statements (for example, Output 15.4.2) shows that each table has an associated template as well as a name. In particular, the template associated with PROC GLM's ANOVA table is called 'Stat.GLM.Tests'.

You can use the 'Stat.GLM.Tests' template to display the SAS data set HistTests, as follows:

   data _null_ ;
   title2 'Listing of the Selections, Using a Standard Template';
      set HistTests;
      file print ods=(template='Stat.GLM.Tests');
      put _ods_;
   run;

The ODS= option in the FILE statement enables you to use the DATA step to display a data set as a table. You do this by specifying data columns and associated attributes, such as the template specification.

The PUT statement contains the _ODS_ keyword. The keyword instructs the PUT statement to send the data values for all columns (as defined in the ODS= option in the FILE statement) to the open ODS destinations. For more information on using ODS in the DATA step, refer to The Complete Guide to the SAS Output Delivery System.

Output 15.10.3: Listing of the Data Sets Using a Standard Template

                                Histamine Study

 Source                     DF             SS    Mean Square   F Value   Pr > F

 Drug                        1     5.99336243     5.99336243      2.71   0.1281
 Depleted                    1    15.44840703    15.44840703      6.98   0.0229
 Drug*Depleted               1     4.69087508     4.69087508      2.12   0.1734
 Time                        3      .              .             24.03   0.0001
 Time_Drug                   3      .              .              5.78   0.0175
 Time_Depleted               3      .              .             21.31   0.0002
 Time_Drug_Depleted          3      .              .             12.48   0.0015


The data set contains the appropriate information, and it is presented in an easily understandable format, using the 'Stat.GLM.Tests' template.

Customizing Your Output

Suppose that you now want to modify the template used to format the ANOVA tables in order to emphasize significant effects. The following statements provide an example of how you can use the TEMPLATE procedure to

For detailed information on using the TEMPLATE procedure, refer to the chapter titled "The Template Procedure" in The Complete Guide to the SAS Output Delivery System.

    proc template;
       define table CombinedTests;
          parent=Stat.GLM.Tests;

          header "#Histamine Study##";
          footer "#* - Test computed using Hotelling-Lawley trace";

          column Source DF SS MS FValue ProbF Star;

          define SS;
             parent = Stat.GLM.SS;
             format = D7.3;
             translate _val_ = . into '   *';
          end;
          define MS;
             parent = Stat.GLM.MS;
             format = D7.3;
             translate _val_ = . into '   *';
          end;
          define Star;
             compute as ProbF;
             translate _val_ >  0.05  into "",
                       _val_ >  0.01  into "*",
                       _val_ >  0.001 into "**",
                       _val_ <= 0.001 into "***";
             pre_space=1 width=3 just=l;
          end;
       end;
    run;

The Dw.s format, used in the preceding statements to redefine the SS and Mean Square columns, writes numbers in similar ranges with the same number of decimal places. In the format specification, w represents the width of the field and s represents the number of significant digits. Refer to the chapter on formats in SAS Language Reference: Dictionary for detailed information.

The following statements display the HistTests data set using the customized template. The results are displayed in Output 15.10.4.

   data _null_;
   title2 'Listing of the Selections, Using a Customized Template';
      set HistTests;
      file print ods=(template='CombinedTests');
      put _ods_;
   run;

Output 15.10.4: Listing of the Data Sets Using a Customized Template: Histamine Study

                                Histamine Study

                                    Sum of       Mean
 Source                      DF    Squares     Square    F Value    Pr > F

 Drug                         1      5.993      5.993       2.71    0.1281
 Depleted                     1     15.448     15.448       6.98    0.0229 *
 Drug*Depleted                1      4.691      4.691       2.12    0.1734
 Time                         3       *          *         24.03    0.0001 ***
 Time_Drug                    3       *          *          5.78    0.0175 *
 Time_Depleted                3       *          *         21.31    0.0002 ***
 Time_Drug_Depleted           3       *          *         12.48    0.0015 **

                * - Test computed using Hotelling-Lawley trace

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.