Customize your SAS® Output with the Template Procedure: A Beginning Tutorial - PowerPoint PPT Presentation

Loading...

PPT – Customize your SAS® Output with the Template Procedure: A Beginning Tutorial PowerPoint presentation | free to download - id: 3d5bb2-NGIwN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Customize your SAS® Output with the Template Procedure: A Beginning Tutorial

Description:

Customize your SAS Output with the Template Procedure: A Beginning Tutorial Carol Gosselin North Carolina State University, Raleigh, NC Joy Munk Smith – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 66
Provided by: statNcsu
Learn more at: http://www.stat.ncsu.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Customize your SAS® Output with the Template Procedure: A Beginning Tutorial


1
Customize your SAS Output with the Template
Procedure A Beginning Tutorial
  • Carol Gosselin
  • North Carolina State University, Raleigh, NC
  • Joy Munk Smith
  • North Carolina State University, Raleigh, NC

2
Topics
  • Review ODS
  • What are Templates?
  • Working with Predefined Templates
  • Creating your own Style and Table Templates
  • Using your new templates

3
Review ODS
  • Output object A basic tabular or graphical
    representation of output. Made up of a data
    component and a template component.
  • Data component Collection of raw numbers and
    strings that make up the table or graph.
  • Template component A set of instructions that
    describe how ODS should format and present the
    raw data.

4
Available Output Destinations
  • Version 8.0
  • LISTING - classic SAS output
  • HTML Hyper Text Markup Language
  • OUTPUT - SAS datasets
  • PRINTER postscript(ps) or printer control
    language(pcl)
  • Version 8.1 additions
  • PRINTER Adobe Acrobat(pdf)
  • RTF - Rich Text Format(rtf)

5
More about Output Destinations
  • Output is sent to all open destinations.
  • LISTING is the only destination open by
    default.
  • HTML, PRINTER, and RTF, destinations must be
    closed before the results can be used or viewed.
  • Be sure to include a RUN and QUIT statement
    before closing a destination or the procedure
    output may not be sent to the destination.

6
General HTML Example
  • ODS html file temp.htm
  • Sascode
  • Run Quit
  • ODS html close

7
General RTF Example
  • ODS rtf filetemp.rtf
  • Sascode
  • Run Quit
  • ODS rtf close
  • Compatible with WORD97 and above. Experimental in
    8.0 production in 8.1. (Olinger 2000)

8
General Postscript Example
  • ODS printer filetemp1.ps ps
  • Sascode
  • Run Quit
  • ODS printer close
  • The ps option forces the creation of a postscript
    file no matter what printer driver you are using.

9
ODS Trace Statement
  • ODS trace on ODS trace on / listing
  • ODS trace off
  • Displays name, label, template, and path of each
    output object generated.
  • The name displayed can be used to select the
    output objects to be sent to any open destination.

10
ODS Trace with Proc Freq
  • Ods trace on /listing
  • Proc freq
  • Tables ssrace
  • Run
  • Ods trace off

11
ODS Trace with Proc Freq
  • In the output window
  • Output Added
  • Name OneWayFreqs
  • Label One-Way Frequencies
  • Template Base.Freq.OneWayFreqs
  • Path Freq.SRACE.OneWayFreqs
  • Also the proc freq results.

12
ODS Trace with Proc Glm
  • SAS code
  • ODS trace on / listing
  • Proc glm class sresid
  • Model satvsresid
  • Lsmeans sresid
  • run

13
ODS Trace with Proc Glm
  • Name Template
  • ClassLevels stat.glm.classlevels
  • Nobs stat.glm.nobs
  • Overallanova stat.glm.overallanova
  • Modelanova (ss1) stat.glm.modelanova
  • Modelanova (ss3) stat.glm.modelanova
  • Means stat.glm.lsmeans

14
Selecting Output Objects
  • OVERALL and destination specific selection and
    exclusion lists determine which objects are sent
    to each destination.
  • Modifying Selection Lists
  • Example
  • ODS html select onewayfreqs
  • ODS listing select all (default)
  • ODS listing exclude overallanova
  • ODS select all (for OVERALL list)

15
Checking Selection Lists
  • To display selection lists
  • ODS destination SHOW
  • For example ODS html show
  • This command will print the selection and
    exclusion lists for the HTML destination and also
    the overall selection and exclusion lists.


16
Persist Option
  • Selection/Exclusion lists are reset to their
    default settings at each program step boundary,
    unless the PERSIST option is specified.
  • Examples
  • ODS html select onewayfreqs persist
  • ODS listing select onewayfreqs persist
  • ODS listing exclude overallanova persist

17
HTML Output Destination
  • Filename htmldoc "e\student\ "
  • ODS html pathhtmldoc
  • File'table1.htm'
  • Contents'table1c.htm'
  • Frame'table1f.htm'
  • Stylestyles.mystyle
  • Stylesheet style.css(urlstyle.css)

18
Support for CSS
  • Note In ODS for Dummies Olinger states Use of
    style sheets will minimize the size of your HTML
    files. CSS support is experimental in release 8.0
    and production in release 8.1

19
LISTING Destination
  • Traditional SAS output
  • Open by default
  • Default selection list is ALL
  • Examples
  • ODS listing ODS listing close
  • ODS listing select outputobject
  • ODS listing exclude outputobject

20
ODS References
  • Bryant, Muller, Pass, ODS, Yes! Odious, No! An
    Introduction to the SAS Output Delivery System.
    SUGI 25 Proceedings, 2000. www.unc.edu/lkbryant/i
    ntro_ods
  • Olinger, C. R., ODS for Dummies, SUGI 25
    Proceedings, 2000. www.sas.com/base/rnd
  • SAS Institute, The Complete Guide to SAS Output
    Delivery, Version 8

21
TEMPLATES
22
Table and Style Templates
  • Table and Style templates are the two main types
    of templates.
  • Table templates provide instructions for
    formatting a single output object.
  • Style templates provide presentation instructions
    for all output objects produced. Style templates
    create a consistent appearance of all SAS output.

23
Table Templates
  • Many table templates are shipped with SAS and
    they are used for displaying the output objects.
  • Table templates control data column order, column
    headers and footers, and data formatting.
  • A table template can be bound to an output object
    in a data step.

24
Style Templates
  • Style Templates
  • Control the look and feel of the whole SAS job
  • There are 16 styles shipped with SAS 8.0
  • Sample code
  • ODS html path htmldoc
  • file table1.htm
  • style styles.minimal

25
Where are Templates Stored?
  • Templates are stored in a new file type called
    item stores.
  • Template stores can have read or update access.
  • For obvious reasons, you should never provide
    update access to the template store that contains
    the SAS provided templates.

26
Where are these Template Stores?
  • SAS defines 2 template stores.
  • SASUSER.TEMPLAT(UPDATE)
  • This template store is listed first in the
    search path and it has update access so user
    created templates are stored here.
  • SASHELP.TMPLMST(READ)
  • This template store has read only access and
    it contains the SAS provided templates. Do not
    provide update access to this file.

27
Providing Access to Template Stores
  • The ODS PATH statement identifies template
    stores, defines search order, and assigns
    read/write permissions.
  • Default settings
  • ODS path sasuser.templat(update)
  • sashelp.tmplmst(read)

28
Default Template Store Path
  • Code
  • Ods path show
  • Results in the Log Window with the default
    settings
  • The current ODS path list is
  • SASUSER.TEMPLAT(UPDATE)
  • SASHELP.TMPLMST(READ)

29
Storing Templates
  • User created templates are stored in
    SASUSER.TEMPLAT because it is the first template
    store with update access in the path.
  • This can be modified with the PATH statement.
  • Never give write access to SASHELP.TMPLMST

30
SettingTemplate Path
  • ODS path
  • work.temp(update)
  • sashelp.tmplmst(read)
  • Note You can use the work space and the template
    store will be temporary. If the template store
    does not exist it will be created.

31
Viewing Contents of Template Store
  • In the Results Window
  • Right click on the Results Folder and select
    Templates
  • Double click on selected Template Store
  • Double click on selected folder
  • Double click on selected template. (or right
    click and select open, edit, delete, etc.)

32
Template Browser
33
Viewing Template Code Method 2
  • To view the template code using SAS code
  • Proc template
  • Source styles.minimal
  • Source styles.default
  • Run
  • The template code will be printed in the log
    window.

34
Why Style Templates?
  • Style templates are used to provide consistent
    appearance to all SAS output.
  • Typically style templates control aspects like
    fonts and colors of foreground, background, text.
  • Style templates can also provide instructions for
    adding graphics to every page.

35
A Simple Style Template Definition
  • Proc Template
  • Define style styles.mydefault
  • Style Data / font_size4
  • Style Header / font_faceitalic
  • Style Systemtitle / backgroundwhite
  • End
  • This is a single style definition with 3 style
    elements having one attribute each.

36
Style Template Syntax
  • Define statement begins the style definition and
    requires a matching end statement. In the
    example, the style name is styles.mydefault .
  • Style statements provide attributes for style
    elements. In the example, the style elements are
    data, header, and systemtitle.

37
So you want to be an expert?
  • Olinger(1999) states, There are approximately
    sixty-five different style attributes that can be
    specified on a style element. For a complete
    list, refer to the documentation.
  • I counted 101 style elements in styles.default.
  • ? Cant wait for the certification test on this!

38
Using Your New Style
  • Code
  • ODS html filetable1.htm
  • stylestyles.mydefault
  • SAS program statements
  • Run Quit
  • HTML close
  • Explanation
  • The style option on the ODS statement is used to
    select a style template. If the requested
    template isnt found the default will be used.

39
Style Element Attributes
  • Font and color are two commonly set style element
    attributes.
  • These will be covered at an introductory level in
    these slides and in our examples.

40
Defining Font Attributes
  • A font definition has the following format
  • (font-face1,font-size, keyword list)
  • Font-face If you specify more than one, the
    browser uses the first one installed on the
    system.
  • Font-size Interpretation of font-size depends on
    the browser

41
Font Attributes (cont.)
  • Keywords
  • Font_weight
  • medium, bold, demi_bold, extra_bold, light
  • Font_style
  • italic, roman, slant
  • Font_width
  • normal, compress, extra_compressed, narrow,
    wide

42
Font Attributes (cont.)
  • Code
  • Style data / font(Arial, Helvetica,4,bold
    italic)
  • Style data / font_faceArial, Helvetic
  • font_size4 font_styleitalic
    font_weightbold
  • Explanation
  • These two statements generate the same results.

43
Color Attributes
  • Some web safe colors (Template Tutorial)
  • RedFF0000 BrassB5A642
  • Green00FF00 BrownA62A2A
  • Blue0000FF Bronze8C7853
  • WhiteFFFFFF MagentaFF00FF
  • Black000000 CopperB87333
  • YellowFFFF00 Cadet Blue5F9F9F

44
Inheritance
  • Often the easiest way to create a template is to
    modify an existing template. This is done using
    inheritance.
  • There are two types of inheritance.
  • Style definition inheritance uses the PARENT
    statement within a style definition.
  • Style element inheritance uses the FROM option
    on the STYLE statement.

45
Style Definition Inheritance
  • Code
  • Proc template
  • Define styles.mydefault
  • parentstyles.default
  • When you use parent all the style elements,
    attributes, and settings from the parent style
    are inherited.

46
Style Definition Inheritance
  • When using style definition inheritance you
    can
  • Modify existing style elements
  • Add new style elements

47
Style Element Inheritance
  • Proc template
  • Define styles.mydefault
  • parentstyles.default
  • Style document / attributes
  • Style data from document / attributes
  • Style header from footer / attributes
  • End

48
Style Element Inheritance
  • Using style element inheritance you can
  • Inherit style elements from within the current
    definition.
  • Inherit style elements from the parent when a
    PARENT statement is used.
  • Note attributes are inherited from the parent if
    the style element doesnt exist within the
    current (child) definition.

49
Style Element Inheritance
  • Inherited style elements inherit all the
    attributes set in the parent.
  • The style elements can be modified and added to.

50
A Sample Table Template
  • Proc template
  • Edit stat.glm.test as combined.tests
  • Edit ss format 7.2 end
  • Edit ms format 7.2 end
  • Run

51
Bind Template to Output Object
  • Data _null_ set object
  • File print ods(templatecombined.test)
  • Put _ods_
  • Run

52
Test Statement
  • Proc template
  • Test datadata_set_name
  • Run
  • This code will test the most recently created
    template. Data set variable names must match
    template column names.

53
Delete Template
  • Proc template
  • Delete combined.tests
  • Run
  • It may be desirable to delete your template if it
    has the same name as a SAS supplied template.
    Why? As long as you have a template with the same
    name as a default template, yours will be used.

54
Storing Your Table Templates
  • Just like with style templates, your table
    templates will be stored in the first template
    store that has update access.
  • You can use the work directory.
  • ODS path work.templat(update)
  • sashelp.tmplmst(read)
  • Templates would be stored temporarily. If
    work.templat doesnt exist it will be created.

55
Using Your Template Method 1
  • With the default path setting
  • If your table template has the same name as a SAS
    Institute supplied template and is stored in
    SASUSER.TEMPLAT, it will be used instead of the
    Institute supplied template. This is because the
    template store SASUSER.TEMPLAT is searched before
    SASHELP.TMPLMST.

56
Using Your Template Method 2
  • You can bind your template with the
  • output object in a data step using the
  • FILE statement with the ODS
  • and TEMPLATE options.

57
Using Your Template Method 2
  • Code
  • data _null_
  • Input a b c
  • file print ods( templatemytemplate
  • columns( col1a col2b col3c ) )
  • put _ODS_
  • Note
  • These 2 methods will be covered in the examples.

58
Proc Template References
  • Heffner(1998) ODS The DATA Step Knows, SUGI 23
    Proceedings, 1998.
  • Olinger(2000), Twisty Little Passages, All
    AlikeODS Templates Exposed., SUGI25
    Proceedings.
  • SAS Institute, The Complete Guide to the SAS
    Output Delivery System, Version 8.

59
Proc Template References (cont.)
  • SAS(2000), The Template Tutorial,
  • PDF http//www.sas.com/rnd/base/topics/temp
    lateFAQ/
  • HTML http//www.sas.com/rnd/base/topics/tem
    plateFAQ/Template.htmlintro

60
Proc Template Tutorial
  • http//www.sas.com/rnd/base/topics/templateFAQ
  • Question and example format
  • Examples mostly modifying styles.default
  • Colors
  • Flyover, tool tips
  • Links
  • margins

61
Sample ProgramsCarol Gosselin
62
TABULATE Code Used in Examples
  • PROC TABULATE DATA b
  • FORMAT 8.0
  • FORMAT senrstat statfmt iof ioffmt.
  • CLASS senrstat iof
  • TABLE iof ALL, SENRSTAT ALL
  • TITLE 'Enrollment by Residency'
  • RUN

63
Data Used in Examples
  • Fictional student data containing the following
    variables
  • IOF Residency (AIn-State, BOut-of-State,
    CInternational)
  • SENRSTAT Enrollment Status (1New, 2Transfer,
    3Continue, 4Reenter)

64
Conclusion
PROC TEMPLATE is a powerful tool for modifying
SAS output. It takes a significant amount of
time to master PROC TEMPLATE, but creating simple
templates is not hard.
65
Contact Information
  • Carol Gosselin -- carol_gosselin_at_ncsu.edu
  • Joy Munk Smith -- joy_smith_at_ncsu.edu
  • Examples are available at
  • http//www.stat.ncsu.edu/sas/ods/templates
About PowerShow.com