Previous Page | Next Page

TEMPLATE Procedure: Creating Crosstabulation Table Templates

Example 1: Creating a Customized Crosstabulation Table Template with No Legend


PROC TEMPLATE features:

DEFINE CROSSTABS statement:

crosstabs-attributes statements

CELLVALUE statement

DEFINE CELLVALUE statement:

CELLSTYLE AS statement

END statement

FORMAT= attribute

HEADER= attribute

LABEL= attribute

DEFINE HEADER statement:

END statement

SPACE= attribute

STYLE= attribute

TEXT statement

DEFINE FOOTER statement:

END statement

DYNAMIC statement

SPACE= attribute

STYLE= attribute

TEXT statement

END statement

FOOTER statement

HEADER statement

NOTES statement

Other ODS features:

ODS HTML statement

ODS PATH statement

DEFINE STYLE statement



Program Description

The following example creates the crosstabulation table template Base.Freq.CrossTabFreqs. The template has the following features:


Program

 Note about code
 Proc Format;
   Value Govtfmt -3='Council Manager'
                  0='Commission'
                  3='Mayor Council'
                 .N='Not Applicable'
                  .='   ?';
   Value Robfmt   1='100 or  Less'
                  2='101-200'
                  3='201-300'
                  4='Over 300'
                 .N='Not     Known'
                  .='   ?';
   Value Colfg   1='yellow'
                  2='red'
                  3='blue'
                  4='purple'
                 .N='green'
                  .='black'
                  other='black';
   Value Rowfg   -3='red'
                  0='purple'
                  3='blue'
                 .N='green'
                  .='black'
                  other='black';   

run;

data gov;
   Label Citygovt='City Government Form'
        Robgrp='Number of Meetings Scheduled';
   Input Citygovt Robgrp Weight;  Missing N;
   Format Citygovt Govtfmt. Robgrp Robfmt.;
   LOOP: OUTPUT; WEIGHT=WEIGHT-1; IF WEIGHT>0 THEN GOTO LOOP;
   DROP WEIGHT;
datalines;
0 1  6  
0 3  3  
0 2  7  
0 4  5  
N N 10 
-3 1 47 
-3 3 49 
-3 2 63 
-3 4 52  
. 2  1  
3 1 31  
3 2 37  
3 3 27  
3 4 55  
3 .  1  
; 
 Note about code
ods path (prepend) work.templat(update);
ods noproctitle;

 
proc template;
   define style white;
      parent=styles.default;
      style body /
         backgroundcolor=white;
      style systemtitle /
         backgroundcolor=white
         fontsize=6
         fontweight=bold
         fontstyle=italic;
      style systemfooter /
         backgroundcolor=white
         fontsize=2
         fontstyle=italic;
      style proctitle /
         backgroundcolor=white
         color=#6078bf
         fontweight=bold
         fontstyle=italic;
    end;
 Note about code
   define crosstabs Base.Freq.CrossTabFreqs;
      notes "Crosstabulation table";
 Note about code
      style=table {backgroundcolor=#BFCFFF};
      cell_style=data {backgroundcolor=#FFFFF0};
      row_var_style=rowheader {backgroundcolor=#BFCFFF  color=rowfg.};
      col_var_style=header {backgroundcolor=#BFCFFF  color=colfg.};
      row_total_style=data {backgroundcolor=#F0F0F0};
      col_total_style=data {backgroundcolor=#F0F0F0};
      grand_total_style=datastrong {backgroundcolor=#F0F0F0};
      legend_style=header {backgroundcolor=#BFCFFF color=#6078bf fontstyle=italic};
 Note about code
      rows_header=RowsHeader cols_header=ColsHeader;
      label = "Frequency Counts and Percentages";
 Note about code
      define header TableOf;
	        text "Table of " _ROW_LABEL_ " by " _COL_LABEL_ / _ROW_LABEL_ ^= '' 
             & _COL_LABEL_ ^= '';
	        text "Table of " _ROW_LABEL_ " by " _COL_NAME_  / _ROW_LABEL_ ^= '';
	        text "Table of " _ROW_NAME_  " by " _COL_LABEL_ / _COL_LABEL_ ^= '';
	        text "Table of " _ROW_NAME_  " by " _COL_NAME_;
         style=header {backgroundcolor=#BFCFFF color=#6078bf fontstyle=italic};
         end;
 Note about code
      define header RowsHeader;
         text _ROW_LABEL_ / _ROW_LABEL_ ^= '';
         text _ROW_NAME_;
         style=header {backgroundcolor=#BFCFFF color=#6078bf fontstyle=italic};
         space=0;
         end;
 Note about code
      define header ColsHeader;
         text _COL_LABEL_ / _COL_LABEL_ ^= '';
         text _COL_NAME_;
         style=header {backgroundcolor=#BFCFFF color=#6078bf fontstyle=italic};
         space=1;
         end;
 Note about code
   define header ControllingFor;
      dynamic StratNum StrataVariableNames StrataVariableLabels;
      text "Controlling for" StrataVariableNames / StratNum > 0;
      style=header;
      end;
 Note about code
      define footer Missing;
         dynamic FMissing;
         text "Frequency Missing = " FMissing -12.99 / FMissing ^= 0;
         style=header {backgroundcolor=#BFCFFF color=#6078bf fontstyle=italic};
         space=1;
         end;

      define footer NoObs;
         dynamic SampleSize;
         text "Effective Sample Size = 0" / SampleSize = 0;
         space=1;
         style=header;
         end;
 Note about code
      define cellvalue Frequency;
         header="";
         label="Frequency Count";
         format=BEST7.; data_format_override=on; print=on;
         cellstyle _val_ < 10 as datastrong {color=green},
                   _val_ > 40 & _val_ < 50 as datastrong {color=orange},
                   _val_ >= 50 as datastrong {color=red};
         end;

      define cellvalue Expected;
         header="";
         label="Expected Frequency";
         format=BEST6. data_format_override=on print=on;
         end;

      define cellvalue Deviation;
         header="";
         label="Deviation from Expected Frequency";
         format=BEST6. data_format_override=on print=on;
         end;

      define cellvalue CellChiSquare;
         header="";
         label="Cell Chi-Square";
         format=BEST6. print=on;
         end;

      define cellvalue TotalPercent;
         header="";
         label="Percent of Total Frequency";
         format=6.2 print=on;
         end;

      define cellvalue Percent;
         header="";
         label="Percent of Two-Way Table Frequency";
         format=6.2 print=on;
         end;

      define cellvalue RowPercent;
         header="";
         label="Percent of Row Frequency";
         format=6.2 print=on;
         end;

      define cellvalue ColPercent;
         header="";
         label="Percent of Column Frequency";
         format=6.2 print=on;
         end;

      define cellvalue CumColPercent;
         header="";
         label="Cumulative Percent of Column Frequency";
         format=6.2 print=on;
         end;
 Note about code
      cellvalue
         Frequency Expected Deviation
         CellChiSquare TotalPercent Percent
         RowPercent ColPercent CumColPercent;
 Note about code
      header TableOf ControllingFor; 
      footer NoObs Missing;
      end;
 Note about code
ods html file='MyCrosstabsTable.html' style=white;
 Note about code
title "City Government Form by Number of Meetings Scheduled";
footnote "Cellvalues are stacked in the following order:";
footnote2  "Frequency";
footnote3 "Percent";
footnote4 "Row Percent";
footnote5 "Column Percent";
ods noproctitle;
 Note about code
proc freq;
    tables citygovt*robgrp / missprint;
run;
 Note about code
ods html close;

Output

Output Using Customized Crosstabulation Table Template

[Output Using Customized Crosstabulation Table Template]

Output Using Default Crosstabulation Table

[Output Using Default Crosstabulation Table]

Previous Page | Next Page | Top of Page