26
Using the new Version 8 Template Procedure for Complete Control of SAS Output Style and Format David Ghan Technical Training Specialist SAS, Canada

David Ghan Technical Training Specialist SAS, Canada

  • Upload
    badrani

  • View
    45

  • Download
    0

Embed Size (px)

DESCRIPTION

Using the new Version 8 Template Procedure for Complete Control of SAS Output Style and Format. David Ghan Technical Training Specialist SAS, Canada. Objective demonstrate the power of Proc Template to customize SAS output format - PowerPoint PPT Presentation

Citation preview

Page 1: David Ghan Technical Training Specialist SAS, Canada

Using the new Version 8 Template Procedure

for Complete Control

of SAS Output Style and Format

David GhanTechnical Training SpecialistSAS, Canada

Page 2: David Ghan Technical Training Specialist SAS, Canada

Objective

• demonstrate the power of Proc Template to customize SAS output format

• outline the general framework for how this is done and introduce some key concepts for starting with Proc Template.

Page 3: David Ghan Technical Training Specialist SAS, Canada

Output Delivery System (ODS)

Page 4: David Ghan Technical Training Specialist SAS, Canada

ODS Destinations

Report DestinationsReport Destinations

Listing HTML

Printer

Data DestinationData Destination

Output

RTF

Page 5: David Ghan Technical Training Specialist SAS, Canada

Output

Listing

HTML

RTF

Destination

OutputObject

Data Component

TemplateComponents

SASData Set

Output Window

HTMLFile

RFT File

Result

ODS Output Production

* Pre-defined templates provided, but can customize

Page 6: David Ghan Technical Training Specialist SAS, Canada

Why Use ODS and Proc Template?

• form and appearance matter.

• automate the formatting process•production jobs• applications• make results accessible to users in their preferred form.

• no post-production point-and-click.

Page 7: David Ghan Technical Training Specialist SAS, Canada

Template Types

• Table• column• header• footer

•Style• Presentation• Colors• Fonts

• There are specific table template for each type of output object.

• A single style template affects the general look of all the output within a given document.

J ob Code

J obCode Frequency PercentCumulativeFrequency

CumulativePercent

BAGCLK 140 6.76 140 6.76

BAGSUP 18 0.87 158 7.63

CHKCLK 125 6.04 283 13.67

CHKSUP 18 0.87 301 14.54

FACCLK 124 5.99 425 20.53

FACMGR 17 0.82 442 21.35

RouteNumber

FirstClassFareYear

1

BusinessFareYear1

EconomyFareYear1

FirstClassFareYear2

BusinessFareYear2

0000001 $1,600.00 $1,090.00 $531.00 $1,942.00 $1,323.00

0000002 $1,600.00 $1,090.00 $531.00 $1,942.00 $1,323.00

0000003 $1,761.00 $1,201.00 $585.00 $2,139.00 $1,458.00

0000004 $1,761.00 $1,201.00 $585.00 $2,139.00 $1,458.00

0000005 $176.00 $120.00 $58.00 $213.00 $145.00

0000006 $176.00 $120.00 $58.00 $213.00 $145.00

0000007 $993.00 $677.00 $330.00 $1,206.00 $822.00

0000008 $993.00 $677.00 $330.00 $1,206.00 $822.00

Page 8: David Ghan Technical Training Specialist SAS, Canada

style template

table template

style elements

attributes

values

table header footer column

attributes

values

attributes

values

attributes

values

attributes

values

The general structure of templates

Page 9: David Ghan Technical Training Specialist SAS, Canada

Objectives

• projected airfares on all flight routes in 3 seat classes over 4 years.• a frequency report for number of employees in different job classes.

Projected Ticket Rates

Route First Class Business Economy First Class Business Economy Number Fare Year 1 Fare Year1 Fare Year1 Fare Year2 Fare Year2 Fare Year20000001 $1,600.00 $1,090.00 $531.00 $1,942.00 $1,323.00 $645.00 0000002 $1,600.00 $1,090.00 $531.00 $1,942.00 $1,323.00 $645.000000003 $1,761.00 $1,201.00 $585.00 $2,139.00 $1,458.00 $711.000000004 $1,761.00 $1,201.00 $585.00 $2,139.00 $1,458.00 $711.000000005 $176.00 $120.00 $58.00 $213.00 $145.00 $71.000000006 $176.00 $120.00 $58.00 $213.00 $145.00 $71.00 . . . . . . . . . . . . . .

Counts by Job Code Job Code

Job Cumulative CumulativeCode Frequency Percent Frequency PercentƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒBAGCLK 140 6.76 140 6.76BAGSUP 18 0.87 158 7.63CHKCLK 125 6.04 283 13.67CHKSUP 18 0.87 301 14.54FACCLK 124 5.99 425 20.53 . . . . . . . . . .

Page 10: David Ghan Technical Training Specialist SAS, Canada

Objectives (cont’d)

• Create the SAS output in HTML format and RTF (Rich Text Format) using standard templatesstandard templates supplied by SAS.

• heading text• data formats• order of columns

• banner imagebanner image (HTLM)• background imagebackground image (HTML)• panels (RTF)• page orientation (RTF)

• Create and use modified templatesmodified templates to produce the HTML and RTF output.

• font• color• traffic lighting

Page 11: David Ghan Technical Training Specialist SAS, Canada

The Plan:

Step 1 - create procedure output as text.

Step 2 - create RTF and HTML output with “default” templates.

Page 12: David Ghan Technical Training Specialist SAS, Canada

The Plan:

Step 3 - Part A - modify style template to specify:• font• font size• landscape layout (RFT)• banner and background images (HTML).

Part B - apply new style template to create output.

Step 4 - Part A - modify table template for Proc Freq to specify:

• order and format of columns• header text• 2 panels per page (RTF)• traffic lighting.

Part B - apply new table template to create output.

Page 13: David Ghan Technical Training Specialist SAS, Canada

Output

Listing

HTML

RTF

Destination

OutputObject

Data Component

TemplateComponents

SASData Set

Output Window

HTMLFile

RTF File

Result

ODS Output Production

proc report,proc freq

style template, table template

Page 14: David Ghan Technical Training Specialist SAS, Canada

Step 1 - create procedure output as text.

proc report data=airline.rates(obs=50) nowd split=' ';title 'Projected Ticket Rates';

columns rte_id _numeric_; define rte_id / id;run;

proc freq data=airline.employees; table JobCode; title 'Counts by Job Code';run;

Page 15: David Ghan Technical Training Specialist SAS, Canada

ODS RTF file=‘something.rtf’;ODS HTML file=‘something.html’;

<original SAS code producing output>

ODS RFT CLOSE;ODS HTML CLOSE;

Step 2 - create RTF and HTML output with “default” templates.

Page 16: David Ghan Technical Training Specialist SAS, Canada

Step 3 - Part A - modify style template to specify font, font size, landscapelayout (RFT), and banner and background images (HTML).

PROC TEMPLATE; DEFINE STYLE style-name; PARENT=parent; REPLACE element1

attribute1=value attribute2=value …;

REPLACE element2attribute1=valueattribute2=value …;

END;RUN;

Element attribute value _document background image something.gif

column headers text color bluebackground color whitefont Lucidia Console

cell borders thickness 2 pixelscolor black

Page 17: David Ghan Technical Training Specialist SAS, Canada

Step 3 - Part B - apply new style template to create output.

ODS RTF file=‘something.rtf’ style=newstyle;ODS HTML file=‘something.html’ style=newstyle;

<original SAS code producing output>

ODS RFT CLOSE;ODS HTML CLOSE;

Page 18: David Ghan Technical Training Specialist SAS, Canada

Step 4 - Part A - modify table template for Proc Freq to specify order and format of columns, header text, 2 panels per page (RTF), and traffic lighting.

PROC TEMPLATE; EDIT TABLE template-name; MVAR; COLUMN column(s); DEFINE header; attribute1=value …; END; EDIT column; HEADER='label text'; FORMAT=format.;

… other change statements… END; END;RUN;

Attributes and values can be specified for:• the entire table• table headers and footers• individual column headers and column values

J ob Code

J obCode Frequency PercentCumulativeFrequency

CumulativePercent

BAGCLK 140 6.76 140 6.76

BAGSUP 18 0.87 158 7.63

CHKCLK 125 6.04 283 13.67

CHKSUP 18 0.87 301 14.54

FACCLK 124 5.99 425 20.53

FACMGR 17 0.82 442 21.35

Page 19: David Ghan Technical Training Specialist SAS, Canada

Step 4 - Part B - apply new table template to create output.

SAS matches up the data component of each output object with the template component by name.

User modified table templates retain the same name as the originals, but they are stored in a different location.

By default, SAS will find and use the user defined table templates first. No need to specify the new table template.

An ODS PATH statement can be used to control which templates SAS is able to find and use.

Page 20: David Ghan Technical Training Specialist SAS, Canada

Process:

• what do I want to change?

• what are the corresponding style elements of the style template? (and/or) • what is the name of the table template and the names of the headers or columns within that I want to change?

• what particular attributes do I want to specify for these style elements, or for the tables, table headers, or table columns?

• what are valid values to set for these attributes?

*Everything in red italics has a specific name

Employees in diff erent jobclassesas of 22MAR01

# ofEmps.

CumFreq J obCode Pct

CumPct

140 140 BAGCLK 6.8 6.8

18 158 BAGSUP 0.9 7.6

125 283 CHKCLK 6.0 13.7

18 301 CHKSUP 0.9 14.5

124 425 FACCLK 6.0 20.5

17 442 FACMGR 0.8 21.4

60 502 FACMNT 2.9 24.3

36 538 FINACT 1.7 26.0

53 591 FINCLK 2.6 28.6

Page 21: David Ghan Technical Training Specialist SAS, Canada

style template

table template

style elements

attributes

values

table header footer column

attributes

values

attributes

values

attributes

values

attributes

values

The general structure of templates

This is the forest. Don’t get lost among the many trees

Page 22: David Ghan Technical Training Specialist SAS, Canada

Template inheritance:

• within a style template, elements inherit attributes and their values from other elements.

• both style and table templates may also inherit elements and their attributes from other templates.

Page 23: David Ghan Technical Training Specialist SAS, Canada

proc template; define style Styles.Default;

. . . . style Container

font = Fonts('DocFont') foreground =

colors('docfg')background = colors('docbg');

style Index from Container foreground = colors('contentfg')

background = colors('contentbg');

. . . .

proc template; define style Styles.Rtf; parent = styles.printer; style titleAndNoteContainer from titleAndNoteContainer / outputwidth = _undef_; replace cell from container / linkcolor = colors('link2');

Inheritance within a style template:

Inheritance from another style template:

Page 24: David Ghan Technical Training Specialist SAS, Canada

Inheritance from another table template:

proc template; edit Base.Freq.OneWayFreqs; . . .

Page 25: David Ghan Technical Training Specialist SAS, Canada

Help and documentation:

• SAS Online Doc - Guide to the Output Delivery System.

• includes syntax• full lists of elements, attributes, and values.(hardcopy useful)

• Interactive Template Window and Template Browser Window.

• get to know the default templates you need to work with• copy and paste required code.

• Classroom Training: Getting Started with the Output Delivery System.

Page 26: David Ghan Technical Training Specialist SAS, Canada

Other references:

• URLs of Interest: www.sas.com/rnd/base/topics/ odsxml/xml.pdf odsprinter/faq.html odscss/ odsfordata/ods.pdf style-template/style.html v6v8ods/index.html

• V7/V8 and ODS papers to download:http://ftp.sas.com/techsup/download/v7papers/