PROC TEMPLATE features: |
DEFINE STYLE statement
| STYLE statement with user-defined attributes |
| DEFINE TABLE statement
| CLASSLEVELS= table attribute |
| DYNAMIC statement |
| MVAR statement | |
| DEFINE
COLUMN statement
| BLANK_DUPS= |
| GENERIC= |
| HEADER= |
| STYLE= | | |
DEFINE
COLUMN statement
| BLANK_DUPS= attribute |
| CELLSTYLE-AS statement |
| GENERIC= attribute | |
DEFINE
FOOTER statement
|
|
Other ODS features: |
ODS HTML statement |
ODS LISTING statement |
FILE statement with ODS= option |
PUT statement with _ODS_
argument |
|
Data set: |
GRAIN_PRODUCTION
|
Format: |
$CNTRY.
|
This example creates a style definition that is equivalent to
the style definition that Creating a Stand-alone Style Definition
creates. However, this style definition uses user-defined attributes to specify
colors and fonts. This technique makes it possible to easily make changes
in multiple places in your output.
| proc template;
define style newstyle2;
style fonts /
"cellfont"=("arial, helvetica", 4, medium roman)
"headingfont"=("arial, helvetica", 5, bold roman)
"titlefont"=("arial, helvetica", 6, bold italic); |
| style colors /
"light"=white
"medium"=cxaaaaff
"dark"=cx0000ff
"bright"=red; |
| style cellcontents /
background=colors("dark")
foreground=colors("light")
font=fonts("cellfont");
style header /
background=colors("medium")
foreground=colors("dark")
font=fonts("headingfont");
style systemtitle /
background=colors("light")
foreground=colors("bright")
font=fonts("titlefont");
style footer from systemtitle /
font_size=3;
style table /
cellspacing=5
borderwidth=10
bordercolorlight=colors("medium")
bordercolordark=colors("dark"); |
| end;
run; |
| proc template;
define table table1; |
| mvar sysdate9; |
| dynamic colhd; |
| classlevels=on; |
| define column char_var;
generic=on;
blank_dups=on;
header=colhd;
style=cellcontents;
end; |
| define column num_var;
generic=on;
header=colhd;
style=cellcontents;
end; |
| define footer table_footer;
text 'Prepared on ' sysdate9;
end; |
| end;
run; |
| ods listing close; |
| ods html body='newstyle2-body.htm'
style=newstyle2; |
| title 'Leading Grain Producers';
title2 'in 1996'; |
| data _null_;
set grain_production;
where type in ('Rice', 'Corn') and year=1996; |
| file print ods=(
template='table1' |
| columns=(
char_var=country(generic=on format=$cntry.
dynamic=(colhd='Country'))
char_var=type(generic dynamic=(colhd='Year'))
num_var=kilotons(generic=on format=comma12.
dynamic=(colhd='Kilotons'))
)
); |
| put _ods_;
run; |
| ods html close;
ods listing; |
Specifying Colors and Fonts with User-Defined Attributes
This HTML output is identical to HTML Output Produced with a New Style Definition, which was produced with a style definition
that used predefined style attributes. You can use the colors and fonts to
confirm that SAS titles use the systemtitle
style element, that column headers use the header
style element, that the footer uses the table-footer
style element, and that the contents of both character and numeric cells use
the cellcontents style element. Use the width
of the table border, the border colors, and the spacing between cells to confirm
that the table itself is rendered with the table
style element.
|
|
In the program in Creating a Stand-alone Style Definition,
if you want to change the color scheme so that the blues are replaced by pink
and red, you must change each occurrence of "blue" and "very
light blue". In this program, because colors are defined as user-defined
attributes, you need to make the change only once. To make this change, you
need only change the following section of code from
style colors /
"light"=white
"medium"=cxaaaaff
"dark"=cx0000ff
"bright"=red;
to
style colors /
"light"=white
"medium"=pink
"dark"=red
"bright"=red;
Similarly, to change the font in any style element that uses cellfont
, you can change the following section of code from
"cellfont"=("arial, helvetica", 4, medium roman)
to
"cellfont"=("courier, arial, helvetica", 4, medium roman)
The following HTML output shows the results of running the same program
with these changes.
Changing Colors and Fonts with User-Defined Attributes
You can see that colors have changed from shades of blue to red and
to pink and that the font face that is used in the cells is now Courier. These
changes occur in multiple places even though you made only one change to the
code for each attribute.
|
|
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.