1
Practically Perfect PresentationsUsing ODS and PROC REPORT
PharmaSUG 2007 Hands-On WorkshopBy: Cynthia Zender
2
Today's AgendaModify PROC REPORT defaults to change elements of PROC REPORT output– HEADER cells– DATA cells– SUMMARY cells– LINE output using ODS STYLE= overrides
Apply conditional formatting at the column, cell or row level Modify table attributes that control interior table lines and table bordersUse logos or images in outputProduce "Page x of y" page numbering for RTF and PDF output.
2
3
Chapter 6: Using Options with ODS
4) Inserting Images and Performing Traffic Lighting
3) Overriding Style for LINES and CALL DEFINE
2) Style= Statement Level Overrides
1) Basic PROC REPORT, ODS Style= and ESCAPECHAR
4
Proc Report Review – Pen and Paper ActivityMatch the statement with its function in PROC REPORT:
A: DEFINE
B: COLUMN
C: DISPLAY
D: COMPUTE/ENDCOMP
E: ACROSS
1: defines a block of code to be executed
2: specifies that variable values should be listed without ordering or grouping
3: specifies that a column is created for every variable value
4: specifies how to use a report item
5: specifies which report items are used on the report
3
5
Review Material for PROC REPORT SyntaxThe following material can be used as reference throughout the Workshop. The correct answer to the review quiz can be found on Slide # 20, Page 10.
6
About the REPORT ProcedurePROC REPORT produces
detail reports in data storage orderdetail reports in sorted order from unsorted datasummary reports based on grouping variables summary rows (group subtotals and overall report totals) for both detail and summary reportsstatistics for analysis variablescustom text.
4
7
Using the Report Procedure
PROC REPORT DATA=library.filename <option(s)>;COLUMN column-specification(s); DEFINE report-item / <usage> <attribute(s)>
<option(s)> ; COMPUTE report-item </ type-specification>;
. . . select SAS language elements . . . ENDCOMP; BREAK location break-variable</ option(s)>; RBREAK location </ option(s)>;
RUN;
PROC REPORT DATA=library.filename <option(s)>;COLUMN column-specification(s); DEFINE report-item / <usage> <attribute(s)>
<option(s)> ; COMPUTE report-item </ type-specification>;
. . . select SAS language elements . . . ENDCOMP; BREAK location break-variable</ option(s)>; RBREAK location </ option(s)>;
RUN;
General form of the REPORT procedure:
8
Reviewing the PROC REPORT Statement
PROC REPORT DATA=library.filename NOWD <option(s)>; PROC REPORT DATA=library.filename NOWD <option(s)>;
The NOWINDOWS | NOWD option specifies how to generate the report. The NOWD option is important if you are using the Output Delivery System.With the NOWD option, the report is sent to the LISTING window and open ODS destinations in non-interactive mode.Without the NOWD option, the report is generated in the REPORT window, an interactive environment in which to develop a report.
5
9
Reviewing the PROC REPORT StatementSelected PROC REPORT statement options:
PANELS=*Specify the number of panels on each page of the report.
PS=*Specify the number of lines in a page of the reportLS=*Specify the length of a line of the report.
SPLIT=Specify the split character. The default split character is a forward slash (/).
BOX*Use formatting characters to add line-drawing characters to the report.
Use ThisTo Do This
HEADSKIP*Write a blank line beneath all column headers.
HEADLINE*Underline all column headers and the spaces between them.
* Listing destination only
10
Reviewing the COLUMN Statement
COLUMN column-specification(s); COLUMN column-specification(s);
column-specification(s) is one or more of the following: report items such as the name of a data set variable, computed variable, or a statistica comma operator to nest or stack columnsparentheses to group columnsheaders to span columnsan alias for a column.
6
11
COLUMN Statement ExamplesSome COLUMN statement examples:
list report items such as the name of a data set variable, computed variable, or a statistic
list an alias for a column.
column Region District N Sales;
column Region Sales Sales=SLmedian;
12
Comma and Parentheses ExamplesThe COLUMN statement also supports use of:
a comma operator to nest or stack columns
parentheses and a comma operator to nest or stack columns
parentheses and headers to span columns.
column Product Sales,N Sales,Mean;
column Region Product,(Sales N);
column Region ('-Cosmetic Division-' Product Sales);
7
13
Specifying a DEFINE Statement
wherereport-item is a data set variable, a statistic, column alias, or a computed column that has been listed in the COLUMN statementusage is DISPLAY, ORDER, GROUP, ACROSS, ANALYSIS, or COMPUTEDattributes define the format, width, spacing, statistic for analysis variable, or sort sequence of the column options specify the label and justification.
DEFINE report-item / <usage> <attribute(s)> <option(s)> ; DEFINE report-item / <usage> <attribute(s)> <option(s)> ;
The DEFINE statement specifies HOW to use a report item:
14
Specifying DEFINE Statement Usages
Compute the variable value from statements within a compute block.
Summarize these variables when there is a GROUP variable and/or a BREAK or RBREAK statement.
Use the variable values as the column headers in the report.
Summarize analysis variables based on the group variables and consolidate into one row all observations that have the same value for the group variable.
Present the data in the default order or the order specified by the ORDER= option.
Present the data in the order in which it is stored.To Do This
COMPUTED
ANALYSIS
ACROSS
GROUP
ORDER
DISPLAYUsage
8
15
Identifying DEFINE Statement OptionsDEFINE statement options alter the report appearance for a particular column.
FORMAT=Format data
SPACING= *Number of blanks to the left of a column
WIDTH= *Column width
Use This OptionTo ModifyLEFT | RIGHT | CENTER
Justification
MISSINGConsider missing values as valid values for the item
NOPRINTPrinting of columnORDER=Order of data values'Variable Label'Column headings The order
of the options after the slash does not matter.
Selected DEFINE statement options:
* Listing destination only
16
Creating Column SummariesTo create a summary for the entire report, use the RBREAK statement.
BREAK BEFORE | AFTER break-variable / <options>;BREAK BEFORE | AFTER break-variable / <options>;
RBREAK BEFORE | AFTER / <options>;RBREAK BEFORE | AFTER / <options>;
To create a summary for groups of data, use the BREAK statement.
The break-variable is a group or order variable. When the value of the break-variable changes, PROC REPORT creates a summary line.
9
17
Using RBREAK and BREAK Options
UL*Underline each value.
SUPPRESSSuppress the printing of the value of the break variable in the summary line and of any underlining or overlining in the break lines in the column that contains the break variable.
SUMMARIZEWrite a summary line in each group of break lines.SKIP*Write a blank line for the last break line.
PAGEStart a new page after the last break line.
DUL*Double-underline each value.
OL*Overline each value.
DOL*Double-overline each value.
Use This Option
To Do This
* Listing destination only
18
Customizing Text for Breaks
When a variable is not specified, the compute block is executed either before or after the report is created. The _PAGE_ option specifies that the compute block is executed either before or after the page break. There must be a BREAK statement with the PAGE option in order to use the _PAGE_ option in a COMPUTE statement. The executable statements can calculate variables, use IF…THEN logic, write out custom text, or use most DATA step statements.
COMPUTE BEFORE | AFTER <variable> <_PAGE_> /;executable statements
ENDCOMP;
COMPUTE BEFORE | AFTER <variable> <_PAGE_> /;executable statements
ENDCOMP;
10
19
Using a COMPUTE Statement
BEFOREReport-itemat a break immediately before the last row of a set of rows. If there is a default summary on that variable, immediately after the creation of the preliminary summary line.
BEFORE_PAGE_*immediately after printing any titles. (LISTING only)
BEFORENo targetat the end of the report.
AFTERNo targetat the end of the report.
AFTER_PAGE_ *near the bottom of each page, immediately before any footnotes. (LISTING only)
Report-item
Use This Target
AFTERat a break immediately after the last row of a set of rows. If there is a default summary on that variable, immediately after the creation of the preliminary summary line.
Use This LocationTo execute the compute block
If the target is _PAGE_, you can specify a justification option,LEFT, RIGHT, or CENTER.
20
Proc Report Review – SolutionsThe correct answers are:
A/4: DEFINE - specifies HOW to use a report item
B/5: COLUMN - specifies WHICH report items are used on the report
C/2: DISPLAY - specifies that variable values should be listed without ordering or grouping
D/1: COMPUTE/ENDCOMP - defines a block of code to be executed
E/3: ACROSS - specifies that a column is created for every variable value
11
21
Your Turn: Submit Demo Programs 1) Submit Demo1a.sas, Demo1b.sas and Demo1c.sas
and review the output. These demonstration programs illustrate basic REPORT procedure and ODS output file creation.
22
Your Turn: Demo01d.sas 1) Submit Step 1 code, and review the output. Answer
the following question:a) What destination(s) used the PANELS= option?
2) Then, submit step 2 code, review the output and review the SAS log. Answer the following question:
a) What destination(s) used the COLUMNS= options?
12
23
YYYYCENTER
YYNYNUMBER and PAGENO=1YYY
YYYY
LISTING
NNNRepeat Character in Spanning HeaderNNNLSNNNSKIP
NNNDOL/DULNNNSPACINGNNNWIDTHNNNHEADLINE/HEADSKIP
RTF
PDFHTMLStatement or Option
ODS destinations do not all use PROC REPORT Options the same way.
Summary of Demo Results
24
Summary of Global System Options
ORIENTATION=CENTER | NOCENTERTOPMARGIN=BOTTOMMARGIN=LEFTMARGIN=RIGHTMARGIN=
PAGENO=
DATE | NODATENUMBER | NONUMBER
RTFPDFHTML
13
25
STYLE= Option
The STYLE= option specifies the style template to use. Style templates describe how to display the presentation aspects of the output.To get a listing of the style templates supplied by SAS, submit the following code:
STYLE= style template
RTFPDFHTML
proc template;list styles / store=sashelp.tmplmst;
run;
26
ODS ESCAPECHARThe ODS ESCAPECHAR statement sets an escape character that is used to introduce special sequences for in-line formatting.
Choose a unique character that does not occur in your code or output.
ods escapechar = 'escape-character';ods escapechar = 'escape-character';
14
27
ODS ESCAPECHARExamples of ODS ESCAPECHAR statement:
The ODS ESCAPECHAR statement can be omitted entirely if you use one of the following as the escape character:
'03'x(*ESC*)
ods escapechar = '!';ods escapechar = '*';ods escapechar = '~';ods escapechar = '^';ods escapechar = '#';
28
ODS ESCAPECHAR
Inserts raw text into the current cell.
Raw Text
Performs a function to get specialized formatting effects within a cell.
Function
Inserts special codes, line breaks, line wraps, and non-breaking space.
Miscellaneous
Modifies the style of the current cell based on the specified style attributes.
Style
DescriptionCategories of Special
Sequences
15
29
Function
{dagger}{thispage}
{sub text}
{lastpage}
{super text}
{pageof}
RTFPDFHTML
The escape character followed by a function creates a specialized formatting effect within a cell.
30
Your Turn: Using STYLE= Option and Override1) Modify the Demo01c.sas program to use the STYLE=
option as shown below and resubmit the programs.
2) Modify the Demo1a.sas program to use the ODS ESCAPECHAR option as shown below:
ods html file='Demo01c.html' style=Analysis;
ods pdf file='Demo01c.pdf' style=Sasweb;
ods rtf file='Demo01c.rtf' style=Journal;
<after ODS invocation statements>ods escapechar='~';footnote j=r 'Page ~{pageof};footnote2 j=c 'Page ~{thispage} of ~{lastpage}';
16
31
Practically Perfect Tip #1If you are creating RTF output, you can use ODS ESCAPECHAR and Style attributes to insert RTF control strings into your result output.
Tip01.sas
footnote j=l font='Arial' h=10.1pt"^S={protectspecialchars=off " "pretext='\brdrt\brdrs\brdrw1 '}""\~";
32
References
http://www.sas.com/rnd/base/index.htmlhttp://www.sas.com/rnd/base/topics/templateFAQ/repoption.htmlhttp://www.w3schools.com/css/css_reference.asp#list
17
33
Chapter 6: Using Options with ODS
4) Inserting Images and Performing Traffic Lighting
3) Overriding Style for LINES and CALL DEFINE
2) Style= Statement Level Overrides
1) Basic PROC REPORT, ODS Style= and ESCAPECHAR
34
The STYLE= Statement Level OverrideGeneral form of the STYLE= statement level override option:
With PROC REPORT, you provide the component name for the STYLE= override option directly in selected PROC REPORT statements.
STYLE(component)={attribute-1=value-1 …attribute-n=value-n}
STYLE(component)={attribute-1=value-1 …attribute-n=value-n}
The STYLE= option is placed after a slash (/) in all the statements except the PROC REPORT statement.
18
35
Using PROC REPORT Components
PROC REPORT
PROC REPORTCOMPUTE RBREAK | BREAK
PROC REPORTRBREAK | BREAK
PROC REPORTDEFINE
PROC REPORTDEFINE
PROC REPORT
Use in This Statement
Cells identified by a CALL DEFINE statement
Calldef
Summary lines generated by BREAK or RBREAK statements
Summary
Lines generated by LINE statements
Lines
Data cellsColumn
Column header cellsHeader (HDR)
Report as a whole and table structure attributes
ReportAffects This Part of ReportComponen
t
36
Style Attributes and Color Values
black, cx000000, h0000000BORDERCOLOR
white, red, yellow, black
cxFFFFFF, cxFF0000,cxFFFF00, cx000000h000FF00, h07880FF,h0B480FF, h0000000
FOREGROUNDBACKGROUND
Sample ValuesAttribute
19
37
Visual Guide to Report Components
Column
Header
Summary
Report
Demo02.sas
38
Font Related Attributes and Sample Values
compressed, narrow, wideFONT_WIDTH
medium, bold, lightFONT_WEIGHT
italic, romanFONT_STYLE
5, 10 pt, 1 cm, 0.25 in FONT_SIZE
"Times New Roman" Arial
Helvetica'Courier New'
"Arial, Helvetica, Helv"
FONT_FACE
Sample ValuesAttribute
20
39
Alternate Font Attribute
('Arial, Helvetica, Helv', 2)("Times, Times New Roman", 3 cm, bold)
(Verdana, 4, bold italic)('Courier New, Courier', 2, italic)
FONT
Sample ValuesAttribute
40
Your Turn: Using STYLE= Option and Override1) Modify the Demo01c.sas program to use the STYLE=
statement level override option as shown below and resubmit the programs.
a) Which destination output was clearly affected by the {font_weight=bold} override?
2) Open and submit the Demo02.sas program. Then review the code and answer the following questions:
a) What style attribute is set to CYAN?b) What style attribute is set to RED?
proc report data=HW03.salesdata nowd ls=115headline headskip spacing=10
style(summary)=Header{font_weight=bold};
21
41
Other Table/Cell Style Attributes
0, 7, .1 in, 1 cm, em, ex, ptCELLSPACINGCELLPADDING
left, dec, center, rightl, d, c, r
JUST
top, middle, bottomt, m, b
VJUST
150, 2 in, 5 cm, 20%
URL'www.sas.com'
"http://support.sas.com"
CELLWIDTHCELLHEIGHT
Sample ValuesAttribute
42
Your Turn: Changing Font and Cellheight1) Modify the Demo01c.sas program to use the STYLE=
statement level override option as shown below and resubmit the programs.
proc report data=HW03.salesdata nowd ls=115headline headskip spacing=10
style(summary)=Header{font_weight=boldcellheight=.75in}
style(column)={font_face='Courier New'};
22
43
Other Style Attributes
n (number of units to indent)INDENT
ON, OFFASIS
PROTECTSPECIALCHARSNOBREAKSPACE
150, 3 in, 20 cm, 80%OUTPUTWIDTH
Sample ValuesAttribute
44
Table Structure, Interior Lines and Exterior Frame
ABOVE, BELOW, BOX, HSIDES, VSIDES, LHS,
RHS, VOIDFRAME
ALL, GROUPS, NONE, COLS, ROWSRULES
0, 7, .1 in, 1 cm, em, ex, ptCELLSPACINGBORDERWIDTH
Sample ValuesAttribute
23
45
RULES Style AttributeThe RULES style attribute specifies the types of rules, or interior table lines, to use in a table.
between all columns COLS
between all rowsROWS
no rules anywhere NONE
between the table header and the table and between the table and the table footer, if there is one
GROUPS
between all rows and columns ALL
Creates interior table lines:RULES Value
46
FRAME Style AttributesFRAME specifies the type of frame to use on a table.
no bordersVOID
a border at the left sidea border at the right side
LHSRHS
borders at the top and bottomborders at the left and right sides
HSIDESVSIDES
borders at the top, bottom, and both sidesBOX
a border at the bottomBELOW
a border at the top ABOVE
Creates this kind of frame around the tableFRAME Value
24
47
Your Turn: Changing Structure of Table1) Modify the Demo02.sas program to use each of the
STYLE= statement level override options as shown below and resubmit the program between each change.
a) What was the result of setting CELLSPACING to 0?
proc report data=HW03.salesdata nowdstyle(report)={background=cyan cellspacing=0
bordercolor=black borderwidth=2rules=rows frame=box}
48
Practically Perfect Tip #2There is an interaction between CELLSPACING, BORDERWIDTH and the RULES and FRAMES style attributes.
Tip02.sas
background=cyan cellspacing=0bordercolor=red borderwidth=0rules=rows frame=box
CELLSPACING=0 prevents the CYAN table background from showing around each table cell and BORDERWIDTH=0 prevents the RED border color from being used for the interior table lines.
CELLSPACING=0 prevents the CYAN table background from showing around each table cell and BORDERWIDTH=0 prevents the RED border color from being used for the interior table lines.
HTML Output
25
49
Practically Perfect Tip #3When dealing with very wide tables:
HTML – tables can be as wide as required.RTF & PDF – table width is controlled by the viewer or rendering software. Use these techniques to make wide tables fit:– Set ORIENTATION option to LANDSCAPE in
OPTIONS statement.– Change FONT_SIZE attribute.– Change CELLPADDING style attribute.
Tip03.sas
50
26
51
Chapter 6: Using Options with ODS
4) Inserting Images and Performing Traffic Lighting
3) Overriding Style for LINES and CALL DEFINE
2) Style= Statement Level Overrides
1) Basic PROC REPORT, ODS Style= and ESCAPECHAR
52
Other Methods to Change Style Attributes
Summary
Call Define
Demo03.sas
Lines
Header
27
53
Changing STYLE(LINES)The LINES component changes the style of a line written in a COMPUTE block:
proc report data=HW03.salesdata nowdstyle(report)={background=white cellspacing=0
bordercolor=black borderwidth=2rules=rows frame=box}
style(header)={background=purple foreground=white}style(column)={background=white}style(lines)={font_weight=bold font_size=14pt
just=r vjust=b foreground=black}style(summary)={background=purple foreground=white};
54
CALL DEFINEInside a COMPUTE block, you can use the CALL DEFINE statement to change STYLE attributes:
compute after Region;if upcase(_break_) = 'REGION' and
index(Region,'Europe') gt 0 thencall define(_ROW_,'style',
'style={background=green foreground=white}');endcomp;
28
55
CALL DEFINE SyntaxA CALL DEFINE statement sets the value of an attribute for a particular column or row in the current row.
The CALL DEFINE statement has three arguments.
CALL DEFINE (column-id, attribute-name, value);CALL DEFINE (column-id, attribute-name, value);
1 2 3
56
_ROW_the automatic variable _ROW_This variable identifies the row towhich the compute block is attached.
_COL_the automatic variable _COL_This variable identifies the column towhich the compute block is attached.
'_C1_''_C5_'
a name of the form _Cn_ (in quotes),where n is the column number
'EmpID''Salary.sum'
a character literal (in quotes)
ExamplesA COLUMN-ID can be
CALL DEFINE Syntax 1
29
57
specifies a format for the column'FORMAT'
makes the contents of each cell of the column a link to the specified Uniform Resource Locator (URL)
'URL'
specifies the style element'STYLE'
DescriptionPossible
attribute-namevalues
CALL DEFINE Syntax 2
58
'dollar12.2''myformat.'
'FORMAT'
'MyHTMLPage.html'MYURL (where MYURL is a variable
equal to a URL)'URL'
'STYLE={background=white foreground=red}''STYLE={foreground=cxFF3300 font_weight=bold}''STYLE'
Example valuesattribute-name
CALL DEFINE Syntax 3
30
59
Another CALL DEFINE Example
Demo04.sas
if upcase(_break_) ne 'REGION' then do;if mod(cntr,2) ne 0 then
call define(_ROW_,'style','style={background=cxeeeeee}');
end;else if upcase(_break_) eq 'REGION' then do;
call define(_ROW_,'style','style=Header');end;
60
Another LINE Example
Demo04.sas
compute after Region /style={foreground=white background=white
cellheight=1px font_size=1px};line ' ';
endcomp;
31
61
Other CALL DEFINE Examples
Demo05.sas
FORMAT
STYLE
URL
62
Practically Perfect Tip #4When you need to perform highlighting based on two or more variable values, use the CALL DEFINE statement.
Tip04.sas
if sales.sum gt 500000 andProduct eq 'WrinkAway Creme' then
call define(_ROW_,'style','style={background=yellow}');
32
63
Chapter 6: Using Options with ODS
4) Inserting Images and Performing Traffic Lighting
3) Overriding Style for LINES and CALL DEFINE
2) Style= Statement Level Overrides
1) Basic PROC REPORT, ODS Style= and ESCAPECHAR
64
Traffic LightingTraffic lighting is highlighting individual cells based on the cell’s value. With CALL DEFINE, you can highlight cells, rows or columns based on multiple values.
Red for bad results.
Yellow for neutral results.
Green for good results.
Example:
33
65
Adding Traffic Lighting with FormatsTwo items must be completed in order to modify individual cells within a column:
Create a format referencing the style attribute values with PROC FORMAT.
Refer to the format in the STYLE option in PROC REPORT for the appropriate column.
1
2
66
Adding Traffic LightingCreate the format with the appropriate value for the style attribute you want to change.
proc format;value tlite low -<750000 = 'light red'
750000 - 1200000 = 'light yellow'1200000<- 2000000 = 'light green'
other = 'cx6495ED';run;
1
34
67
Traffic Lighting with FormatRefer to the format in the STYLE= option or CALL DEFINE:
Demo06.sas
define Sales/ sum 'Sales' f=comma16.style(column)={background=tlite.};
68
Your Turn: Using the Correct Format Ranges1) Modify the Demo06.sas program PROC FORMAT as
shown below (eliminate the OTHER format). Rerun the program, review the results and answer the following question:
a) What happened to the summary line when the changed format was used?
proc format;value tlite low -<750000 = 'light red'
750000 - 1200000 = 'light yellow'1200000<- high = 'light green';
run;
35
69
Table/Cell Style Attributes
'C:\Logo.jpg'"PharmaSUG_07.jpg"
PREIMAGEPOSTIMAGE
BACKGROUNDIMAGE"<HR size=3>"
'<a href="www.sas.com"> SAS Web Page</a>'
PREHTMLPOSTHTML
'This is a draft.'"Continue"
PRETEXTPOSTTEXT
DefinitionAttribute
70
Using the PREIMAGE Style AttributeThe location of the image file for HTML is the place where the file will be found when the HTML file is opened by the browser:
proc report data=HW03.salesdata nowdstyle(report)={preimage='PharmaSUG_07.jpg'};title 'Demo 07 - Using Images';
36
71
Your Turn: Using Traffic Lighting for Images1) Modify the Demo07.sas program to use the
POSTIMAGE STYLE attribute override as shown below and resubmit the program.
a) Does the image appear before or after the footnote?proc report data=HW03.salesdata nowd
style(report)={postimage='PharmaSUG_07.jpg'};footnote 'Solution 07 – Using Images';
72
Your Turn: Using Traffic Lighting for Images2) Modify the program a second time to remove the
STYLE(REPORT) option and add the following COMPUTE block.
a) How does the output differ from the previous run?
compute after _page_ /style={preimage='PharmaSUG_07.jpg'};line ' ';
endcomp;
37
73
Practically Perfect Tip #5Even though some PROC REPORT options are not used by all ODS destinations, you can simulate many of the options using the HTMLSTYLE attribute with CSS style properties and values.
The HTMLSTYLE attribute is only used for HTML destination output. However, starting in SAS 9.2, new style attributes will allow you to change attributes like border top and borderbottom in order to simulate PROC REPORT options for RTF and PDF destinations, too.
Tip05.sas
sugar
74
Practically Perfect Tip #6You can also put a corporate logo into the SAS TITLE statement using ODS ESCAPECHAR.
title j=l "~S={preimage='PharmaSUG_07.jpg'}";title2 'Tip 06 - Using a Logo';
Tip06.sas
38
About the Speaker
Speaker
Company
Telephone
Comments & E-Mail
Cynthia Zender
SAS Institute Inc.
(505) 522-3803
76
Top Related