SAS Support
Self Service Support
Assisted Support
Premium Support
Infrastructure Support
Logging a Call
Service Levels
Hints and Tips
 

USING ODS TO CREATE CUSTOMISED OUTPUT

Using the SAS Output Delivery System (ODS), you can create, customise, and manage HTML output in any operating environment by submitting programming statements. After creating HTML files, you can view them using Internet Explorer or Netscape Navigator.

ODS gives you new formatting options and makes procedure output much more flexible. With ODS, you can easily create HTML, RTF, PCL, PS, XML, Latex and PDF output, an output data set of procedure results and traditional SAS listing output. Also, ODS stores your output in its component parts (data and table definition) so that numerical data retains its full precision.

Procedure output is divided into components, or output objects. Depending on the procedure that you run you might have one or several output objects created. For example proc print would create just one output object but proc univariate would produce multiple output objects. ODS stores a link to each output object in the results window. Using ODS programming statements we can control what output objects we are interested in and what ODS destinations we want to send them to.

In order to start creating HTML, RTF, PDF files etc. you will need a few ODS statements to get you started. By default SAS output still goes to the output window. In order to send the output elsewhere you need to open the appropriate destination. The example below turns off the listing destination (the output window) and opens the HTML destination so that it is ready to receive our output. When the HTML destination is closed the class.html file is created and the HTML destination is closed:

  Ods listing close;
  Ods html body='c:\myreports\class.html';
  Proc print data=sashelp.class;
  Run;
  Ods html close;
  Ods listing;

For more information on ODS statements have a look at the section in the online documentation entitled 'The complete guide to the output delivery system'.

Each output object can be broken down into two parts. Firstly we have the data component. This is the actual raw numbers and characters, which make up our SAS output. Secondly there is the template component. This is a description of how the data is to be formatted and arranged. ODS uses two different type of templates, style and table.

Style templates are an abstract description of how ODS should display the presentation aspects of a SAS job. This will include things like colour, font size and font face.

Table templates are used by ODS to control tabular output. This includes things like the text and order of column headers, column ordering and formats for data. Because not all output from SAS procedures can be fitted into a generic table definition there are some procedures that do not use a table template. This includes output from Proc print, proc report and proc tabulate.

Even though these procedures don't use table templates you can still customise the style aspects of your output by using the STYLE= option. The example below right justifies the three variables as well as changing the background colour to red and the font style to italic:

  ods html body='c:\myreports\class.html';
  proc print data=sashelp.class;
  var name age height / style=[just=right FONT_STYLE=italic background=red] ;
  run;
  ods html close;

Proc template can be a tricky procedure to get to grips with but it does give you a very powerful tool with which you can customise your output. For all things ODS you should visit http://support.sas.com/rnd/base/index-ods-resources.html , which is a treasure trove of sample code, FAQ's and tips and tricks. For proc template queries view the FAQ at http://support.sas.com/rnd/base/topics/templateFAQ/Template.html.

Below are five common ODS queries that we often receive in Customer Support:

1. When using the RTF destination Can I get my page numbers in page X of Y format?
2. How can I add a hyperlink to my title?
3. How can I add a background image to the current HTML PAGE?
4. Is there a way to increase the size of the cells in the table?
5. How can I specify a place to break my labels in HTML?

1. When using the RTF destination Can I get my page numbers in page X of Y format?
You can add RTF code in the TITLE or FOOTNOTE statement. Below is an example:

  ods listing close;
  ods rtf file="temp.rtf";
  proc print data=sashelp.class;
  footnote j=r "{\field{\*\fldinst {\b\i PAGE }}}\~{\b\i of}\~{\field{\*\fldinst{\b\i NUMPAGES }}}";
  run;
  proc print data=sashelp.class;
  run;

  ods rtf close;

2. How can I add a hyperlink to my title?
Adding a hyperlink in the title can be done several ways. One way is to add the hyperlink in the TITLE statement. This is shown in example 1. The benefit of this method is that you can specify a different hyperlink for each title. This will only make the specified title a hyperlink.

Starting with Release 8.1, you can add a hyperlink individually in a TITLE statement by using the LINK= option. See example 2.

Another approach would be to use the URL= attribute within the style element SystemTitle. Using this approach, every title would specify the same the same anchor to go to, and every title would be a hyperlink. See example 3.

  /* example 1*/
  title '<a href="http://www.sas.com">this is a title</a>';

  /* example 2*/
  title link="http://www.sas.com/" "this is a test";

  /* example 3*/
  proc template;
   define style styles.test;
    parent=styles.default;
     style systemtitle from titlesandfooters /
      URL='http://www.sas.com';
    end;
   run;

3. How can I add a background image to the current HTML PAGE?
To add a background image to the HTML page, the BACKGROUNDIMAGE= attribute can be used within the style element Body:

  proc template;
   define style styles.background;
    parent=styles.default;
    Style Body from Document /
    backgroundimage='l:\moo4.gif';
   end;
  run;

4. Is there a way to increase the size of the cells in the table?
To increase the size of the cells, the CELLWIDTH attribute can be specified to provide the desired width. This can be specified in the Table style element. The argument is specified in pixels.

  proc template;
   define style styles.test;
   parent=styles.default;
    style Data from Cell /
     cellwidth=100;
   end;
  run;

5. How can I specify a place to break my labels in HTML?
To specify a place to break labels in the HTML file, use the <BR> tag where you want the breaks to occur:

  ods html body='temp.html';

  proc print data=sasuser.class label;
   label sex='<Div>this is<br>label for<br>sex</Div>';
  run;

  ods html close;

Back to Top

Did you find this page useful?

If you have any comments or questions, feel free to contact us.




0845 402 9907