Previous Page | Next Page

Understanding and Customizing SAS Output: The Output Delivery System (ODS)

Customizing ODS Output


Customizing ODS Output at the Level of a SAS Job

ODS provides a way for you to customize output at the level of the SAS job. To do this, you use a style definition, which describes how to show such items as color, font face, font size, and so on. The style definition determines the appearance of the output. The fancyprinter style definition is one of several that is available with SAS.

The following example uses the fancyprinter style definition to customize program output. The output consists of two output objects, Moments and BasicMeasures, that the UNIVARIATE procedure creates. The STYLE= option on the ODS PRINTER statement specifies that the program use the fancyprinter style.

options nodate pageno=1;

ods listing close;
ods printer ps file='style_job.ps' style=fancyprinter; 
ods select Moments BasicMeasures;
 
proc univariate data=sat_scores;
   var SATscore;
   title 'Average SAT Scores for Entering College Classes, 1972-1982*';
   footnote1 '* Recentered Scale for 1987-1995'; 
run;

ods printer close; 
ods listing;

The following output shows the results:

Printer Output: Titles, Footnote, and Variables Printed in Italics

[Printer Output: Titles, Footnote, and Variables Printed in Italics]

For detailed information about style and table definitions, as well as the TEMPLATE procedure, see SAS Output Delivery System: User's Guide.


Customizing ODS Output by Using a Template

Another way to customize ODS output is by using a template. In ODS, templates are called table definitions. A table definition describes how to format the output. It can determine the order of table headings and footnotes, the order of columns, and the appearance of the output. A table definition can contain one or more columns, headings, or footnotes.

Many procedures that fully support ODS provide table definitions that you can customize. You can also create your own table definition by using the TEMPLATE procedure. The following is a simplified form of the TEMPLATE procedure:

PROC TEMPLATE;
DEFINE table-definition;
HEADER header(s);
COLUMN column(s);
END;

The DEFINE statement creates the table definition that serves as the template for writing the output. The HEADER statement specifies the order of the headings, and the COLUMN statement specifies the order of the columns. The arguments in each of these statements point to routines in the program that format the output. The END statement ends the table definition.

The following example shows how to use PROC TEMPLATE to create customized HTML and printer output. In the example, the SAS program creates a customized table definition for the Basic Measures output table from PROC UNIVARIATE. The following customized version shows that

options nodate nonumber linesize=80 pagesize=60; 1 

proc template; 2 
   define table base.univariate.Measures; 3 
   header h1 h2 h3; 4 
   column VarMeasure VarValue LocMeasure LocValue; 5 

   define h1; 6 
      text "Basic Statistical Measures";
      spill_margin=on;
      space=1;
   end;
   define h2; 6 
      text "Measures of Variability";
      start=VarMeasure;
      end=VarValue;
   end;
   define h3; 6 
      text "Measures of Location";
      start=LocMeasure;
      end=LocValue;
   end;

   define LocMeasure; 7 
      print_headers=off;
      glue=2;
      space=3;
      style=rowheader;
   end;
   define LocValue; 7 
      print_headers=off;
      space=5;
      format=7.3;
      style=data{font_style=italic font_weight=bold};
   end;
   define VarMeasure; 7 
      print_headers=off;
      glue=2;
      space=3;
      style=rowheader;
   end;
   define VarValue; 7 
      print_headers=off;
      format=7.3;
      style=data{font_style=italic font_weight=bold};
   end;
end; 8 
run; 9 

ods listing close;
ods html file='scores-body.htm' 10 
     contents='scores-contents.htm'
         page='scores-page.htm'
        frame='scores-frame.htm';
ods printer file='scores.ps'; 11 
ods select BasicMeasures; 12 

title; 
proc univariate data=sorted_scores mu0=3.5; 13 
   var SATscore;
run;

ods html close; 14 
ods printer close; 14 
ods listing; 15 

The following list corresponds to the numbered items in the preceding program:

[1] All four options affect the Listing output. The NODATE and NONUMBER options affect the Printer output. None of the options affects the HTML output.

[2] PROC TEMPLATE begins the procedure for creating a table.

[3] The DEFINE statement creates the table definition base.univariate.Measures in SASUSER.

[4] The HEADER statement determines the order in which the table definition uses the headings, which are defined later in the program.

[5] The COLUMN statement determines the order in which the variables appear. PROC UNIVARIATE names the variables.

[6] These DEFINE blocks define the three headings and specify the text to use for each heading. By default, a heading spans all columns. This is the case for H1. H2 spans the variables VarMeasure and VarValue. H3 spans LocMeasure and LocValue.

[7] These DEFINE blocks specify characteristics for each of the four variables. They use FORMAT= to specify a format of 7.3 for LocValue and VarValue. They also use STYLE= to specify a bold, italic font for these two variables. The STYLE= option does not affect the Listing output.

[8] The END statement ends the table definition.

[9] The RUN statement executes the procedure.

[10] The ODS HTML statement begins the program that uses the customized table definition. It opens the HTML destination and identifies the files to write to.

[11] The ODS PRINTER statement opens the Printer destination and identifies the file to write to.

[12] The ODS SELECT statement selects the output object that contains the basic measures.

[13] PROC UNIVARIATE produces one object for each variable. It uses the customized table definition to format the data.

[14] The ODS statements close the HTML and the PRINTER destinations.

[15] The ODS LISTING statement opens the listing destination for output.

The following display shows the printer output:

Customized Printer Output from the TEMPLATE Procedure

[Customized Printer Output from the TEMPLATE Procedure]

The following display shows the HTML output:

Customized HTML Output from the TEMPLATE Procedure

[Customized HTML Output from the TEMPLATE Procedure]

Previous Page | Next Page | Top of Page