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 • outline the general framework for how this is done and introduce some key concepts for starting with Proc Template. Output Delivery System (ODS) ODS Destinations Report Destinations Listing HTML RTF Printer Data Destination Output ODS Output Production Data Component Output Object Template Components Destination Result Output SAS Data Set Listing Output Window HTML HTML File RTF RFT File * Pre-defined templates provided, but can customize 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. Template Types • Table • column • header • footer •Style • Presentation • Colors • Fonts Route Number First Class Fare Year 1 Business Fare Year1 Economy Fare Year1 First Class Fare Year2 Business Fare Year2 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 Job Code JobCode Frequency Percent Cumulative Cumulative Frequency Percent 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 17 0.82 442 21.35 FACMGR • 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. The general structure of templates style template table template style elements table header footer column attributes attributes attributes attributes attributes values values values values values 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 Number 0000001 0000002 0000003 0000004 0000005 0000006 . . First Class Fare Year 1 $1,600.00 $1,600.00 $1,761.00 $1,761.00 $176.00 $176.00 . . Business Fare Year1 $1,090.00 $1,090.00 $1,201.00 $1,201.00 $120.00 $120.00 . . Economy Fare Year1 $531.00 $531.00 $585.00 $585.00 $58.00 $58.00 . . First Class Fare Year2 $1,942.00 $1,942.00 $2,139.00 $2,139.00 $213.00 $213.00 . . Business Fare Year2 $1,323.00 $1,323.00 $1,458.00 $1,458.00 $145.00 $145.00 . . Counts by Job Code Job Code Job Cumulative Cumulative Code Frequency Percent Frequency Percent ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 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 . . . . . . . . . . Economy Fare Year2 $645.00 $645.00 $711.00 $711.00 $71.00 $71.00 . . Objectives (cont’d) • Create the SAS output in HTML format and RTF (Rich Text Format) using standard templates supplied by SAS. • Create and use modified templates to produce the HTML and RTF output. • heading text • data formats • order of columns • banner image (HTLM) • background image (HTML) • panels (RTF) • page orientation (RTF) • font • color • traffic lighting The Plan: Step 1 - create procedure output as text. Step 2 - create RTF and HTML output with “default” templates. 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. ODS Output Production proc report, proc freq Data Component Output Object Template Components style template, table template Destination Result Output SAS Data Set Listing Output Window HTML HTML File RTF RTF File 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; Step 2 - create RTF and HTML output with “default” templa ODS RTF file=‘something.rtf’; ODS HTML file=‘something.html’; <original SAS code producing output> ODS RFT CLOSE; ODS HTML CLOSE; Step 3 - Part A - modify style template to specify font, font size, landscap layout (RFT), and banner and background images (HTML). PROC TEMPLATE; DEFINE STYLE style-name; PARENT=parent; REPLACE element1 attribute1=value attribute2=value …; REPLACE element2 attribute1=value attribute2=value …; END; RUN; Element document attribute background image value _ something.gif column headers text color background color font blue white Lucidia Console cell borders thickness color 2 pixels black 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; 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; Job Code JobCode Attributes and values can be specified for: • the entire table • table headers and footers • individual column headers and column values Frequency Percent Cumulative Cumulative Frequency Percent 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 17 0.82 442 21.35 FACMGR 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. 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 different jobclasses as of 22MAR01 # of Emps. Cum Freq JobCode Pct Cum Pct 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 The general structure of templates style template table template style elements table header footer column attributes attributes attributes attributes attributes values values values values values This is the forest. Don’t get lost among the many trees 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. Inheritance within a style template: 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'); .... Inheritance from another style template: proc template; define style Styles.Rtf; parent = styles.printer; style titleAndNoteContainer from titleAndNoteContainer / outputwidth = _undef_; replace cell from container / linkcolor = colors('link2'); Inheritance from another table template: proc template; edit Base.Freq.OneWayFreqs; . . . 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. 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/