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

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

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

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

PROC TEMPLATE: The Basics

Lauren HaworthGenentech, Inc.

South San Francisco, CA

Page 2: PROC TEMPLATE: The Basics Lauren Haworth Genentech, 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

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

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

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

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

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

RESULTS

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

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;

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

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

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

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

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

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

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

RESULTS

+ 700 more lines of source code!

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

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

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

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

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

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

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

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

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

RESULTS

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

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

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.

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

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

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

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)

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

RESULTS

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

“HeadersAndFooters”

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

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

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

Changing the fonts

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

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

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

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

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

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

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

HANDS ON: Pasting a Style

1. Insert a blank line below the PARENT= statement

2. Paste the style code there

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

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

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

Changing Typefaces

• Here are some typefaces to try

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

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

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

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

HANDS ON: Changing Typefaces• Reference:

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

Changing Typefaces: My Code

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

Changing Typefaces: My Results

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

Changing Font Sizes

Notice that the title and footnote are the same size.

You may want to make the footnote smaller

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

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

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

HANDS ON: Pasting a Style

1. Insert a blank line above the END statement

2. Paste the style code there

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

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 )

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

HANDS ON: Font Size

1. Use the style attribute FONT_SIZE=

2. Change the 5 to a new value

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

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)

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

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

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

Changing Font Size and Style: My Code

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

Changing Font Size and Style: My Results

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

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

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

More Font Changes: My Code

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

More Font Changes: My Results

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

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

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

More Font Changes: My Code

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

More Font Changes: My Results

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

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

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

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

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

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

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

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

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

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)

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

HANDS ON: Changing Borders

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

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

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)

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

HANDS ON: Changing Rules

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

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

Changing Rules and Borders: My Code

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

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?

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

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

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

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

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

Cell Spacing: My Code

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

Cell Spacing: My Results

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

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

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

HANDS ON: Cell Padding

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

2. Submit the program

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

Cell Spacing: My Code

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

Cell Padding: My Results

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

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

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

Changing the Color Scheme

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

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

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

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

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

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

HANDS ON: Changing the Colors

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

Changing Colors: My Code

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

Changing Colors: My Results

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

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

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

HANDS ON: Changing the Colors

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

Changing Colors: My Code

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

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

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

Changing Colors: My Results

Why is the background still gray?

We need to add one more style element to our code

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

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

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

HANDS ON: Change the Body Colors

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

2. Rerun the program

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

HANDS ON: Changing the Colors

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

Changing Colors: My Code

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

Changing Colors: My Results

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

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

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;

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

Removing the Boxes: My Results

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

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/

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

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

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

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

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

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)

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

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

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

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.

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

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!

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

COLOR REFERENCE

www.laurenhaworth.com [email protected]