Cascading
style sheets (CSS) is a style sheet language that you can use with
ODS to control the look and formatting of ODS output. A cascading
style sheet is an external file that contains label-value pairs that
describe the visual aspects of output, such as fonts, colors, borders,
and so on. You can then apply the CSS to your ODS output. The CSS
language that you can use with ODS is based on the standard CSS syntax
found on the Internet at
http://www.w3.org/Style/CSS/. However, with ODS, you can apply
CSS to many different types of output, such as PDF, RTF, and PowerPoint.
For complete documentation about using CSS with ODS, see the chapter
about CSS in the
SAS Output Delivery System: Advanced Topics.
You can use CSS as an
alternative to PROC TEMPLATE styles. Unlike PROC TEMPLATE styles,
CSS enables you to apply custom styles based on column names, BY group
names, BY group variables, and anchor names. Using CSS with ODS gives
you greater flexibility in customizing your ODS reports.
Using CSS with ODS enables
you to use the power of CSS selectors with the internal data querying
capabilities of PROC TEMPLATE styles. You can create custom output
by defining your own external CSS file to apply to your ODS output.
To use CSS with ODS, it is recommended that you perform the following
steps:
-
Look at the ODS Document
Object Model (ODS DOM) to determine what elements and attributes exist
so that you can construct your CSS selectors to address them. You
can view the ODS DOM with the ODS TRACE DOM;
statement
or with the DOM option in any ODS destination statement except ODS
LISTING and ODS OUTPUT.
-
Create an external CSS
file that consists of standard CSS syntax.
-
Apply the CSS file to
your ODS output with the CSSSTYLE= option in any ODS destination statement
except ODS LISTING, ODS OUTPUT, or ODS POWERPOINT. The style sheet
is interpreted by SAS instead of by the web browser.
In the following example,
the style sheet MyCss.css is applied to PDF, RTF, and HTML output.
ods pdf cssstyle='MyCss.css';
ods rtf cssstyle='MyCss.css';
ods html cssstyle='MyCss.css';
proc print data=sashelp.class(obs=3);
run;
ods _all_ close;
The
following CSS is an external file named ColorMapCss.css:
.body {
background-color: lightblue;
}
.oo {
background-color: pink;
}
.systemtitle {
background-color: darkblue;
color: white;
}
.table {
background-color: white;
}
.header {
background-color: gold;
}
.rowheader {
background-color: purple;
color: white;
}
.data {
background-color: linen;
}
The following SAS code
applies the CSS file ColorMapCss.css to your PDF output:
options nodate nonumber obs=25;
ods html close;
ods pdf nobookmarklist nobookmarkgen file="myoutput.pdf"
cssstyle="your-file-path\ColorMapCss.css";
title "Comparison of City and Highway Miles Per Gallon";
proc print data=sashelp.cars;
var make model type Origin MPG_City MPG_Highway;
run;
ods pdf close;
PDF Output with CSS Applied