• Print  |
  • Feedback  |

FOCUS AREAS

Return to SAS 9

Base SAS

More Enhancements to ODS for SAS 9.2


Introduction

This topic demonstrates many of the new features for ODS in SAS 9.2. See also new features in the various ODS destinations.


ODS TEXT= Statement

This new feature responds to a SASWare ballot item. The ODS statement in SAS 9.2 is enhanced to support the TEXT= option for most destinations.

In SAS 9.1, TEXT= is supported by MARKUP, PRINTER and RTF.

In SAS 9.2, the ODS TEXT= statement supports those destinations plus LISTING and DOCUMENT. (OUTPUT is not supported.) You only have to specify ODS TEXT= once, rather than specifying TEXT= for each destination.

The destinations have always handled text differently because the output types are so different. That is still true with ODS TEXT= in SAS 9.2.

The UserText style governs text specified with ODS TEXT=.

Here is some example code:

  proc template;
     define style mystyle;
     parent=styles.default;
     style usertext from usertext /
           foreground=red;
     end;
  run;

  ods html file="text.html" style=mystyle;
  ods pdf file="text.pdf" startpage=never notoc style=mystyle;
  ods rtf file="text_trad.rtf" style=mystyle;
  ods tagsets.rtf file="text_tagset.rtf" style=mystyle;
  ods xml file="text.xml" style=mystyle;

  ods document name=text(write);

  ods text="text7";
  ods text="text8";

  title "here is a title";
  footnote "here is a footnote";

  proc print data=sashelp.class;
  run;
  ods text="text9";
  ods _all_ close;

  title;
  footnote;

  ods listing;
  proc document name=text;
     list/levels=all;
     replay;
  run;
  quit;

  /*-- clean up temp style --*/

  proc template;
     delete mystyle;
  run;


WHERE Expressions in ODS SELECT and EXCLUDE Statements

SAS customers wanted a way to select a group's worth of output objects. For some customers, this means a BY group. For others, it means a group of graphical displays. For this reason the ODS SELECT and EXCLUDE statements have been enhanced to accept one or more WHERE expressions.

The WHERE expression accepts the following character-typed pseudo-variables: _name_, _label_, _path_, and _labelpath_. These variables contain information about the output object being selected or excluded, for example:

  Output Excluded:
  -------------
  Name:       ExtremeObs
  Label:      Extreme Observations
  Template:   base.univariate.ExtObs
  Path:       Univariate.ByGroup2.b.ExtremeObs
  Label Path: 'The Univariate Procedure'.'a=2'.'b'.'Extreme Observations'
  -------------
  NOTE: The above message was for the following by-group:
        a=2

  Output Added:
  -------------
  Name:       Moments
  Label:      Moments
  Template:   base.univariate.Moments
  Path:       Univariate.ByGroup3.b.Moments
  Label Path: 'The Univariate Procedure'.'a=3'.'b'.'Moments'
  -------------

Here is an example that selects the third of three BY groups of output objects:

  data a;
     do a = 1 to 3;
        do b = a * 10 to a*10+9;
           output;
        end;
     end;

  proc univariate data=a;
     by a;
  ods trace on/label excluded;
  ods select where=(_labelpath_ ? 'a=3');
  run;


Scalable Vector Graphics (SVG)

You can now use W3's Scalable Vector Graphics (SVG) in your ODS output. This should work in PDF and HTML, although you might need to download a plug-in from Adobe.

  options printerpath='SVG';
  goptions dev=SVG;

  title1 'Scalable Vector Graphics';

  ods pdf file="svg.pdf";
  ods html file="svg.html";

  proc gchart data=sashelp.class;
     vbar name/sumvar=height;
  run;

  ods html close;
  ods pdf close;


Using CSS (Cascading Style Sheets)

In SAS 9.2, you can define styles both using TEMPLATE procedure syntax as well as cascading style sheets (CSS). Your CSS file must be similar to the CSS files that get output from ODS HTML. Only CSS classes with names that match ODS style element names will work; other CSS selectors are not supported at the present time. However, you can use the Enterprise Guide Style Editor to create valid styles. Essentially, this means that SAS now ships with a style editor!

The sample code below demonstrates how to create a style definition by importing a CSS file. It also shows how to use a CSS file as a style without ever creating a style definition. In order to use this sample code, you must save the CSS sample as 'mycss.css'.

  proc template;

  /* Define a style definition that imports a CSS file
   * and defines style elements as well. */

     define style styles.mycssstyle;
        /* Import CSS into a Proc Template style definition */
        import "mycss.css";
        class data /
              color = red;
     end;

     define style styles.mycssstyleprinter; parent=styles.mycssstyle;
        /* Import 'print' media definitions from CSS file */
        import 'mycss.css' print;
     end;

  run;

  /* Use the style definition */
  ods html file="css.html" style=styles.mycssstyle;
  ods tagsets.rtf file="css_tag.rtf"  style=styles.mycssstyleprinter;
  ods rtf file="css_trad.rtf"  style=styles.mycssstyleprinter;
  ods pdf file="css.pdf" style=styles.mycssstyleprinter;

  proc contents data=sashelp.class; run;

  ods html close;
  ods pdf close;


  /* Use CSS files directly */
  ods html file="css2.html" cssstyle="mycss.css";
  ods tagsets.rtf file="css2_tag.rtf"  cssstyle="mycss.css"(print);
  ods rtf file="css2_trad.rtf" cssstyle="mycss.css"(print);
  ods pdf file="css2.pdf" cssstyle="mycss.css"(print);

  proc contents data=sashelp.class; run;

  ods html close;
  ods pdf close;

Here is the sample CSS code:

  .body
     {
     background-color: white;
     color: black;
     font-family: times, serif;
     }
  .header, .rowheader, .footer, .rowfooter, .data
     {
     border: 1px black solid;
     color: black;
     padding: 5px;
     font-family: times, serif;
     }
  .header, .rowheader, .footer, .rowfooter
     {
     background-color: #a0a0a0;
     }
  .table
     {
     background-color: #dddddd;
     border-spacing: 0;
     border: 1px black solid;
     }
  .proctitle
     {
     font-family: helvetica, sans-serif;
     font-size: x-large;
     font-weight: bold;
     }
  @media print
     {
    .header, .rowheader, .footer, .rowfooter, .data
        {
        background-color: white;
        }
     }
  


Stripe All Tables in a Report in Five Lines of Code

PROC TEMPLATE has many new features in SAS 9.2. This demo shows off three of them simultaneously: global templates, merged overrides, and new CELLSTYLE-AS variables.

The code below defines a table with the special name of Base.Template.Table. This is the name of the global template that all tables inherit from. It then runs the MEANS and the CONTENTS procedures. In the output, all the tables have rows with alternating colors. If your columns have CELLSTYLE-AS statements in them, those styles merge with the CELLSTYLE-AS doing the row colors (as seen in Base.Template.Column).

  /* Create a global template that all tables will inherit from */
  proc template;
     define table base.template.table;
        cellstyle mod(_row_, 2) and
                  ^(_style_ like '%Header') as {backgroundcolor=#c6faff},
                  ^(mod(_row_, 2)) and
                  ^(_style_ like '%Header') as {backgroundcolor=#80e9ff};
     end;

     /* Just some extra eye candy */
     define column base.template.column;
        cellstyle _val_ > 70 as {color=red};
     end;
  run;

  /* Run some procs */
  ods pdf file="striped.pdf" startpage=no;

  proc means data=sashelp.class;
     class age;
     var height weight;
  run;

  proc contents data=sashelp.class;
  run;

  ods pdf close;