TEMPLATE Procedure: Creating Crosstabulation Table Templates |
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 |
|
The following example creates a new crosstabulation table template for
the CrossTabFreqs table. The template has the following features:
-
a legend with customized text
-
modified headers and
footers
-
variable labels used in headers
-
modified table regions
-
customized styles for
cellvalues
|
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
;
|
|
ods path (prepend) work.templat(update); |
|
proc template;
define crosstabs Base.Freq.CrossTabFreqs;
notes "Crosstabulation table with legend"; |
|
rows_header=RowsHeader cols_header=ColsHeader;
label = "Frequency Counts and Percentages";
grand_total_style=data {fontweight=bold}; |
|
define header ControllingFor;
dynamic StratNum StrataVariableNames StrataVariableLabels;
text "Controlling for" StrataVariableNames / StratNum > 0;
style=header;
end; |
|
define header RowsHeader;
text _ROW_LABEL_ / _ROW_LABEL_ ^= '';
text _ROW_NAME_;
space=0;
style=header;
cindent=';';
end; |
|
define header ColsHeader;
text _COL_LABEL_ / _COL_LABEL_ ^= '';
text _COL_NAME_;
space=1;
style=header;
cindent=';';
end; |
|
define footer TableOf;
notes 'NoTitle is 1 if the NOTITLE option was specified.';
dynamic StratNum NoTitle;
text "Table " StratNum 3. " of " _ROW_LABEL_ " by " _COL_LABEL_ / NoTitle = 0
& StratNum > 0 & _ROW_LABEL_ ^= '' & _COL_LABEL_ ^= '';
text "Table " StratNum 3. " of " _ROW_LABEL_ " by " _COL_NAME_ / NoTitle = 0
& StratNum > 0 & _ROW_LABEL_ ^= '' ;
text "Table " StratNum 3. " of " _ROW_NAME_ " by " _COL_LABEL_ / NoTitle = 0
& StratNum > 0 & _COL_LABEL_ ^= '';
text _ROW_LABEL_ " by " _COL_LABEL_ / NoTitle = 0 & _ROW_LABEL_ ^= ''
& _COL_LABEL_ ^= '';
text _ROW_LABEL_ " by " _COL_NAME_ / NoTitle = 0 & _ROW_LABEL_ ^= '';
text _ROW_NAME_ " by " _COL_LABEL_ / NoTitle = 0 & _COL_LABEL_ ^= '';
text "Table " StratNum 3. " of " _ROW_NAME_ " by " _COL_NAME_ / NoTitle = 0
& StratNum > 0;
text _ROW_NAME_ " by " _COL_NAME_ / NoTitle = 0;
style=header;
end; |
|
define footer Missing;
dynamic FMissing;
text "Frequency Missing = " FMissing -12.99 / FMissing ^= 0;
space=1;
style=header;
end;
define footer NoObs;
dynamic SampleSize;
text "Effective Sample Size = 0" / SampleSize = 0;
space=1;
style=header;
end; |
|
define cellvalue Frequency;
header="Frequency";
format=BEST7.;
label="Frequency Count";
data_format_override=on print=on;
end;
define cellvalue Expected;
header="Expected";
format=BEST6.;
label="Expected Frequency";
data_format_override=on print=on;
end;
define cellvalue Deviation;
header="Deviation";
format=BEST6.;
label="Deviation from Expected Frequency";
data_format_override=on print=on;
end;
define cellvalue CellChiSquare;
header="Cell Chi-Square";
format=BEST6.;
label="Cell Chi-Square";
print=on;
end;
define cellvalue TotalPercent;
header="Total Percent";
format=6.2;
label="Percent of Total Frequency";
print=on;
end;
define cellvalue Percent;
header="Percent";
format=6.2;
label="Percent of Two-Way Table Frequency";
print=on;
cellstyle _val_ > 20.0 as {color=#BF6930};
end;
define cellvalue RowPercent;
header="Row Percent";
format=6.2;
label="Percent of Row Frequency";
print=on;
end;
define cellvalue ColPercent;
header="Column Percent";
format=6.2;
label="Percent of Column Frequency";
print=on;
end;
define cellvalue CumColPercent;
header="Cumulative Column Percent";
format=6.2;
label="Cumulative Percent of Column Frequency";
print=on;
end; |
|
header ControllingFor;
footer TableOf NoObs Missing; |
|
cellvalue
Frequency Expected Deviation
CellChiSquare TotalPercent Percent
RowPercent ColPercent CumColPercent;
end;
run; |
|
title "City Government Form by Number of Meetings Scheduled";
ods html file='MyCrosstabsTableLegend.html' style=ocean; |
|
proc freq;
tables citygovt*robgrp / missprint;
run;
|
|
ods html close; |
Output Using Customized Crosstabulation Table Template
Output Using Default Crosstabulation Table
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.