PROC TEMPLATE: The Basics Lauren Haworth Genentech, Inc. South San Francisco, CA.

Post on 31-Dec-2015

219 views 2 download

Transcript of PROC TEMPLATE: The Basics Lauren Haworth Genentech, Inc. South San Francisco, CA.

PROC TEMPLATE: The Basics

Lauren HaworthGenentech, Inc.

South San Francisco, CA

Stylish ODS

• ODS ships with standard styles– Get the job done– Not exactly stylish

• You can build your own styles– To suit your taste– To meet your business requirements

Today’s Workshop

• Creating a custom style for your output.

• Fast-track approach– Just the basics of the syntax– Copy and paste the code you need

HANDS ON: Create HTML output

1. Open SAS v9 using the shortcut with my name on it

2. The first sample program should be open (if not, open c:\workshops\ws112\SampleProgram1.sas)

3. Submit the program

RESULTS

Syntax: the STYLE= option

• When we issued this ODS command:

ODS HTML FILE=‘sample1.html’;

• We’re really issuing this command:

ODS HTML FILE=‘sample1.html’ STYLE=Default;

Syntax: the STYLE= option

• ODS has a default style it uses for each destination

• To switch to another style, type in an explicit STYLE= option and specify a style name

Syntax: PROC TEMPLATE

• This PROC does many things related to ODS Style and Table definitions

• One key feature: the SOURCE statement– Allows you to view the source code for a style

HANDS ON: use SOURCE statement

1. In SAS, switch back to the program window2. Use the Open button on the menu bar3. Select SampleProgram2.sas4. Review the syntax of the SOURCE

statement5. Submit the program6. Switch to the log window to see the results

RESULTS

+ 700 more lines of source code!

PROC TEMPLATE source code

• Skimming through the code, you’ll see:– Many style definitions– Cover colors, fonts, titles, tables, etc.

• Templates like this are overwhelming to read

• We’ll look at another tool for understanding styles

HANDS ON: Pop-up Styles

1. In SAS, switch back to the program window

2. Use the Open button on the menu bar

3. Select SampleProgram3.sas

4. Find the ODS MARKUP statement

Tagset: style_popup

• This code creates HTML using a tagset:

ods markup file="sample3.html"tagset=tagsets.style_popup;

• The MARKUP destination and tagsets are a whole workshop

• All you need to know is that this technique creates an HTML file with special features

HANDS ON: Pop-up Styles

1. Submit the program

2. Don’t review the results in SAS

3. Instead, open Internet Explorer and openc:\workshops\ws112\sample3.html

RESULTS

If you see the security warning on your output, right click on it, select “Allow blocked content”, and click Yes.

RESULTS

Moving the mouse around highlights different parts of the page, and brings up a label for each part of the output.

This label shows the style element that controls that part of the output.

RESULTSClicking on a highlighted part of the output brings up a popup window with the style definition code

HANDS ON: Find this style

1. In SAS, switch back to the log window

2. Scroll up until you find the log for Sample Program 2

3. Scan through the source code for Style Header (the style we found using the popup tool)

RESULTS

• There’s nothing there. • This doesn’t look like the code from the popup. • Why? • This code references another style

“HeadersAndFooters”

RESULTS

• This still doesn’t look like the code from the popup. • References another style (Cell), and two lists fonts() and

colors().• Backtracking to find all of these items would be time-

consuming• The popup style saves this effort. It shows you all of the

values in one style element

Changing the fonts

HANDS ON: Creating a Custom Style

1. In SAS, switch back to the program window

2. Use the Open button on the menu bar

3. Select SampleProgram4.sas

4. Find the PROC TEMPLATE statement

5. Find the PARENT= statement

Syntax: PROC TEMPLATE

• Allows you to define every aspect of a style

• Can contain hundreds of lines of code.

• To simplify life, we build styles from existing styles– use the PARENT= statement– only specify the things we want to change

HANDS ON: Copying a Style

1. Go back to Internet Explorer

2. Click on the title of the output

3. Find the popup window (if it’s not visible, it may be minimized)

4. Copy the code for the style SystemTitle

5. Switch back to the SAS program window

HANDS ON: Pasting a Style

1. Insert a blank line below the PARENT= statement

2. Paste the style code there

Changing Typefaces

• Use the style attribute FONT_FACE=

• Change to a new value

• For HTML, can list up to 3 fonts (in case your user doesn’t have your 1st-choice font)

• For other destinations, only 1 is used

Changing Typefaces

• Here are some typefaces to try

• These are “safe” because most of your users will have them

HANDS ON: Changing Typefaces

1. Edit the font name in the FONT_FACE= attribute for the title style

2. Submit the program

3. View the output in the results window

4. See what changed

HANDS ON: Changing Typefaces• Reference:

Changing Typefaces: My Code

Changing Typefaces: My Results

Changing Font Sizes

Notice that the title and footnote are the same size.

You may want to make the footnote smaller

HANDS ON: Copying Footnote Style

1. Go back to Internet Explorer

2. Click on the footnote of the output

3. Find the popup window (if it’s not visible, it may be minimized)

4. Copy the code for the style SystemFooter

5. Switch back to the SAS program window

HANDS ON: Pasting a Style

1. Insert a blank line above the END statement

2. Paste the style code there

Changing the font size

• Use the FONT_SIZE attribute

• The value (5) is an HTML font size

• You can replace it with another HTML font size, or you can switch to a value in points( 10pt )

HANDS ON: Font Size

1. Use the style attribute FONT_SIZE=

2. Change the 5 to a new value

Changing the Font Style

• The footnote looks nice in italic, but the title does not

• We can fix that now

• Use the FONT_STYLE attribute

• Values you can use are italic and roman (non-italic)

HANDS ON: Font Style

1. Go to the SystemTitle style

2. Use the style attribute FONT_STYLE=

3. Change the italic to roman

4. Run the program to see the change in the title and footnote

Changing Font Size and Style: My Code

Changing Font Size and Style: My Results

HANDS ON: More Font Changes

1. Use the Popup tool to add the code for the column headers (Style Header) to the PROC TEMPLATE code

2. Change the typeface and style to whatever you want

3. Another attribute you can change is FONT_WEIGHT (values: medium or bold)

4. Make further changes to the headers, title, and footnote, if you like

5. Resubmit the program and review your results

More Font Changes: My Code

More Font Changes: My Results

HANDS ON: More Font Changes

1. Use the Popup tool to add the code for the table cells (Style Data) to the PROC TEMPLATE code

2. Change the typeface, weight, and style to whatever you want

3. Make further changes to the headers, title, and footnote, if you like

4. Resubmit the program and review your results

More Font Changes: My Code

More Font Changes: My Results

Changing Rules and Borders

• Rules are the lines between table cells

• Borders are the lines around tables, table headers, and table footers

• Virtually all ODS output is in the form of tables

HANDS ON: Copying a Style

1. Go back to Internet Explorer

2. Hover the mouse over the borders until the table borders turn red

3. Copy the Table style from the popup window

HANDS ON: Pasting the Style

1. Go back to SAS and paste the style into your PROC TEMPLATE

2. Review the RULES= style and FRAME= style attributes

Changing Rules and Borders

• Lines between cells inside the table are controlled by the Rules style attribute

• Borders around the outside of the table are controlled by the Frame style attribute

Changing Borders

• The Frame attribute is currently set to BOX (borders all of the way around the table)

• Another option is void (no borders)

• Further options:– above, below, rhs, lhs (pick a side)– vsides, hsides (left and right, top and bottom)

HANDS ON: Changing Borders

1. Change the Frame setting to one of the other options by typing over the word box

Changing Rules

• The Rules attribute is currently set to groups (lines between table header/footer and body)

• Other options:– all (lines between all cells)– none (no lines between the table cells)– rows (lines between the rows)– cols (lines between the columns)

HANDS ON: Changing Rules

1. Change the Rules setting to one of the other options by typing over the word groups

Changing Rules and Borders: My Code

Changing Rules and Borders: My Results

Wait a minute – didn’t we just set the rules to none? Where did those white lines come from?

Cell Spacing

• The lines we could see in our table did not come from the table rules

• They were created because the table background (white) was showing through between the table cells

• If the CELLSPACING attribute is >0, then the background shows through

HANDS ON: Cell Spacing

1. Go back to the SAS program and change the CELLSPACING setting in the Table style to 0

2. Submit the program

Cell Spacing: My Code

Cell Spacing: My Results

Cell Padding

• One more attribute is available for tables: CELLPADDING

• Cell padding puts space inside table cells, between the text and the cell borders

• Larger values make table more readable

• Smaller values save space

HANDS ON: Cell Padding

1. Go back to the SAS program and change the CELLPADDING setting in the Table style

2. Submit the program

Cell Spacing: My Code

Cell Padding: My Results

Changing the Color Scheme

• ODS allows you to specify foreground (text) and background colors

• Can use color names: red, green, blue

• Or color hex codes: cxFF0000, cx00FF00, cx0000FF

Changing the Color Scheme

*Warning: some color names have typos in SAS, will get warning messages

Changing the Color Scheme

• To assign a new color:– Pick the correct style element (SystemTitle,

SystemFooter, Header, Data)– change the FOREGROUND and

BACKGROUND values to the colors you want

HANDS ON: Changing the Colors

1. Go back to the PROC TEMPLATE code

2. In the SystemTitle style, type over the hex code for FOREGROUND with the text “red” (minus the quotes

3. Re-run the program and see what happens

HANDS ON: Changing the Colors

Changing Colors: My Code

Changing Colors: My Results

HANDS ON: Changing More Colors

1. Go back to the PROC TEMPLATE code

2. Change more of the FOREGROUND and BACKGROUND settings

3. Re-run the program and see what happens

HANDS ON: Changing the Colors

Changing Colors: My Code

• For SystemTitle, SystemFooter, and Header:FOREGROUND = midnightblueBACKGROUND = white

• For Data and Table:FOREGROUND = black BACKGROUND = white

Changing Colors: My Results

Why is the background still gray?

We need to add one more style element to our code

HANDS ON: Copy/Paste Code

1. Go back to Internet Explorer2. Click on the background of the page (hint:

look at the parts of your output that still have that gray color, and click on the same area in Internet Explorer)

3. Copy the code from the popup (style Body) and paste it into your PROC TEMPLATE

HANDS ON: Change the Body Colors

1. Edit the colors in the Body style element to your choices

2. Rerun the program

HANDS ON: Changing the Colors

Changing Colors: My Code

Changing Colors: My Results

What are those faint gray boxes around the title and footnote?

Removing the Boxes

• This exposes one limitation to using the popup styles:– You can’t click on these boxes, so there’s no

way to find out what code to modify– Solution is in my paper:

STYLE SysTitleAndFooterContainer /CELLSPACING=0;

Removing the Boxes: My Results

Changing Colors: More Tips

• Find a “Color Picker” on the web (Google search on this term)– use the 216-color “web-safe” palette – will help you use hex codes instead of names

for more control

• If you’re not creative, try http://www.colorschemer.com/online/

RTF differences

• Instead of Default style as parent, use RTF• RTF has very narrow page margins (0.25”).

– To change: add style attributes TOPMARGIN, BOTTOMMARGIN, LEFTMARGIN, and RIGHTMARGIN to the Body style element. Set them to a larger value (e.g. 1in).

• You don’t need to list multiple font names• If you are rerunning an ODS RTF program, you need to

close the Results window before resubmitting the job• Titles and footnotes will appear in the page header and

footer, unless you add the option BODYTITLE to your ODS RTF statement

• Sample Program 5 shows these changes

PDF differences

• Instead of Default style as parent, use Printer• If you get a WARNING message “'Font specification

"<fontname>" failed', you may need to register the fonts on your system. Execute the following code to fix the problem:proc fontreg; fontpath "%sysget(systemroot)\fonts";run;

• You don’t need to list multiple font names• If you are rerunning an ODS PDF program, you need to

close the Results window before resubmitting the job• Sample Program 6 shows these changes

Summary

• You’ve now learned the basics of style modification: fonts, colors, rules/borders, spacing

• These techniques will allow you customize most aspects of your output

• You can save your PROC TEMPLATE code, but you don’t need to run it every time (read up on the ODS PATH statement)

Summary

• Some warnings:– The Popup style is very simple– To modify very specific portions of your

output, you will need to add more style elements and settings

– RTF and PDF are a little different

References(no need to write down, they’re all in the proceedings)

• PROC TEMPLATE documentation: – SAS Output Delivery System Users Guide (version 9.1.3 online

documentation) http://support.sas.com/onlinedoc/913/docMainpage.jsp• A CD of additional sample styles:

– Bernadette Johnson, Instant ODS: Style Templates for the SAS Output Delivery System, © 2003, BBU Press, Cary, NC, USA.

• Preliminary documentation of new features and sample programs can be found at:– http://www.sas.com/rnd/base/index-ods-resources.html.

• My book on ODS has a number of chapters on modifying ODS styles: – Haworth, Lauren, Output Delivery System: The Basics, 2001, SAS

Institute Inc., Cary, NC, USA.

FINAL HANDS ON: Tweak your Style

• I’ll be happy to take your questions at this point, or …

• You can use the remaining time to continue to modify your style

• Or, you can play with sample programs 5 and 6

• THANKS FOR COMING!

COLOR REFERENCE

www.laurenhaworth.com info@laurenhaworth.com