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

Example 15.7: Creating an Output Data Set: Subsetting the Data

This example demonstrates how you can create an output data set with the ODS OUTPUT statement and also use data set selection keywords to limit the output that ODS writes to a SAS data set.

The following data set, called Color, contains the eye and hair color of children from two different regions of Europe. The data are recorded as cell counts, where the variable Count contains the number of children exhibiting each of the 15 eye and hair color combinations.

   data Color;
      input Region Eyes $ Hair $ Count @@;
         label Eyes  ='Eye Color'
               Hair  ='Hair Color'
               Region='Geographic Region';
   datalines;
   1 blue  fair   23  1 blue  red     7  1 blue  medium 24
   1 blue  dark   11  1 green fair   19  1 green red     7
   1 green medium 18  1 green dark   14  1 brown fair   34
   1 brown red     5  1 brown medium 41  1 brown dark   40
   1 brown black   3  2 blue  fair   46  2 blue  red    21
   2 blue  medium 44  2 blue  dark   40  2 blue  black   6
   2 green fair   50  2 green red    31  2 green medium 37
   2 green dark   23  2 brown fair   56  2 brown red    42
   2 brown medium 53  2 brown dark   54  2 brown black  13
   ;

In the statements that follow, the SAS listing is closed. The ODS OUTPUT statement creates the "ChiSq" table as a SAS data set called myStats. Note that you can obtain the names of the tables created by any SAS/STAT procedure in the individual procedure chapter or from the individual procedure section of the SAS online Help system. You can also determine the names of tables with the ODS TRACE statement (see Example 15.3 and Example 15.6).

The DROP= data set option excludes variables from the new data set. The WHERE= data set option selects particular observations for output to the new data set myStats.

   ods listing close;

   ods output ChiSq=myStats
              (drop=Table
               where=(Statistic='Chi-Square' or
                      Statistic='Likelihood Ratio Chi-Square'));

In the following statements, the Color data set is first sorted by the Region variable. The FREQ procedure is invoked to create and analyze a crosstabulation table from the two categorical variables Eyes and Hair, for each value of the variable Region.

No ODS destinations are open until the ODS LISTING statement is encountered just prior to the invocation of the PRINT procedure.

   proc sort data=Color;
      by Region;
   run;

   proc freq data=Color order=data;
      weight Count;
      tables Eyes*Hair/testp=(30 12 30 25 3);
      by Region;
      title 'Hair Color of European Children';
   run;

   ods listing;
   proc print data=myStats;
   run;

Output 15.7.1 displays the output resulting from the previous statements.

Output 15.7.1: Output Data Set from PROC FREQ and ODS

                        Hair Color of European Children

   Obs    Region    Statistic                      DF         Value      Prob

    1        1      Chi-Square                      8       12.6331    0.1251
    2        1      Likelihood Ratio Chi-Square     8       14.1503    0.0779
    3        2      Chi-Square                      8       18.2839    0.0192
    4        2      Likelihood Ratio Chi-Square     8       23.3021    0.0030

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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