7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 1/24
Tips and Tricks for Creating the Reports
Your Clients Need to See
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 2/24
Agenda
• Produce a “typical” Demographics table• Produce output according to a pre-defined
layout
• “Jazz it up” with ODS styles
• Goals
• Add to your bag of tricks
• Bridge the gap between PROC REPORT 101
and real-world applications
• Discover how to quickly get answers from
documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 3/24
Agenda
• PROC REPORT tools
• ACROSS variables
• CALL DEFINE
• Temporary variables
• ODS tools
• PROC REPORT-specific styling• In-line formatting
• Using destination-specific language
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 4/24
DEMOGRAPHICS
Treatment Group
Placebo(N=xxx)
Treatment A(N=xxx)
Treatment B(N=xxx)
Agen xxx xxx xxx
Mean (SD) xx(xx) xx(xx) xx(xx)
Median xxx xxx xxx
Min – Max xx-xx xx-xx xx-xx
Gender
Male xxx xxx xxx
Female xxx xxx xxx
Race
Caucasian xxx xxx xxx
Black xxx xxx xxx
Others xxx xxx xxxAsian xxx xxx xxx
Native Hawaiian or other Pacific Islander
xxx xxx xxx
Population subset
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 5/24
Subject treatment Gender Race Age
001 Placebo M Caucasian 17
002 Placebo F Black 15
003 Treatment B F Asian 16
004 Placebo M Black 15
005 Placebo M Caucasian 14
006 Treatment A M Caucasian 15
007 Treatment A M Caucasian 17
008 Treatment B F Black 14
…. ... … …
Typical DEMOGRAPHICS data set
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 6/24
Parameter Text Treatment Values
Age n Placebo 6
Age n Treatment A 7
Age n Treatment B 6
Age Mean (SD) Placebo 13.2 (1.72)
Age Mean (SD) Treatment A 13.0 (1.29)
Age Mean (SD) Treatment B 13.8 (1.60)
Age Median Placebo 13
Age Median Treatment A 12
.... …. ...
Gender Female Treatment A 3 (42.9%)
Gender Female Treatment B 4 (66.7%)
Race Caucasian Placebo 4 (66.7%)
Race Caucasian Treatment A 4 (57.1%)
Summarized DEMOGRAPHICS data set
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 7/24
DEMOGRAPHICS
Treatment Group
Placebo(N=xxx)
Treatment A(N=xxx)
Treatment B(N=xxx)
Age
n xxx xxx xxx
Mean (SD) xxx xxx xxx
Median xxx xxx xxx
Min – Max xxx xxx xxx
GenderMale xxx xxx xxx
Female xxx xxx xxx
Race
Caucasian xxx
Black xxx
Others xxx
Asian xxx
Native Hawaiian or other Pacific Islander
xxx
Population subset
} ORDER1=1
} ORDER1=2
} ORDER1=3
} ORDER2=1
} ORDER2=2
} ORDER2=3
} ORDER2=4
} ORDER2=1
} ORDER2=2
} ORDER2=1
} ORDER2=2
} ORDER2=3
} ORDER2=4
} ORDER2=5
Formatted value of ORDER1
Formatted value of ORDER1
Formatted value of ORDER1
{TEXT
{TEXT
{TEXT
TREATMENT=1 TREATMENT=2 TREATMENT=3
VALUES
ods rtf file='demo1-across1.rtf' style=minima
proc report nowindows data=temp.demo ;
column order1 order2 text … ;
define order1 / group noprint order=internaldefine order2 / group noprint order=internal
define text / group " " ;
…
compute before order1 ;
line @1 " " ;
line @1 order1 header. ;
endcomp;
run;
ods rtf close;
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 8/24
ACROSS Variables
• Each value of the variable becomes a column in the table
• Formatted values become the column headers and thecolumns are ordered from left to right by these formatted
values
• All column are treated the same• Most commonly used by “stacking” or interacting with
other variables or statistics.
• Comparisons with other procedure variables
• PROC TABULATE - Class variables in the column
dimension
• PROC TRANSPOSE – ID variableSee documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 9/24
treatment order1 order2 text values
1 2 1 Male 5
1 2 2 Female 2
2 1 4 Min - Max 11 - 16
3 3 3 Other 2
1 3 2 Black 1
3 1 1 n 6
2 2 2 Female 3
2 3 1 Caucasian 2
3 1 2 Mean (SD) 13.2 (1.33)
…. ... … … …
TEMP.DEMO
ods rtf file=‘demo1-across1.rtf' style=minimal ;
proc report nowindows data=temp.demo ;
column order1 order2 text
define order1 / group noprint order=internal ;
define order2 / group noprint order=internal ;
define text / group " " ;
compute before order1 ;
line @1 " " ;
line @1 order1 header. ;
endcomp;
run;ods rtf close;
proc transpose data=temp.demo out=tran;
by order1 order2 text ;
var values ;
id treatment ;
run;
treatment , values ;
define treatment / across ‘Treatment Group’
order = internal format = treat. ;
define values / group " " ;
ACROSS Variables
X
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 10/24
Placebo(N=xx)
Treatment A(N=xx)
Treatment B(N=xx)
System Organ ClassHigh Level Term
Subject Eventn (%) n
Subject Eventn (%) n
Subject Eventn (%) n
System Organ Class #1 x (xx.x%) x x (xx.x%) x x (xx.x%) x
High Level Term #1 x (xx.x%) x x (xx.x%) x x (xx.x%) x
High Level Term #2 x (xx.x%) x x (xx.x%) x x (xx.x%) xHigh Level Term #3 x (xx.x%) x x (xx.x%) x x (xx.x%) x
…
System Organ Class #2 x (xx.x%) x x (xx.x%) x x (xx.x%) x
High Level Term #4 x (xx.x%) x x (xx.x%) x x (xx.x%) x
High Level Term #5 x (xx.x%) x x (xx.x%) x x (xx.x%) x
High Level Term #6 x (xx.x%) x x (xx.x%) x x (xx.x%) x
ADVERSE EVENTS
proc transpose data=temp.demo out=sub;
by order1 order2 text ;
var subjects ;
id treatment ;
run;
proc transpose data=temp.demo out=ev;
by order1 order2 text ;
var events ;
id treatment ;
run;
Now merge SUB with EV by ORDER1, ORDER, TEXT
Don’t forget to rename!
/* without headers */ columns … treatmnt , (subjects events) … ;
/* with headers */ columns … treatmnt , ((“Subject~n (%)” subjects) (“Event~n” events) ) … ;
See demo1-across1.rtf
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 11/24
“Jazz it up” in style!!• What‟s in a style?
• Formatting
• Non-data text
• PROC REPORT styling
• Syntax
• location, location, location
• Which statements allow for styling?
• Other alternatives
• Destination language
• In-line formatting• Conditional styling
• CALL DEFINE
• Temporary variablesSee documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 12/24
DEMOGRAPHICS
Treatment Group
Placebo(N=xxx)
Treatment A(N=xxx)
Treatment B(N=xxx)
Agen xxx xxx xxx
Mean (SD) xx(xx) xx(xx) xx(xx)
Median xxx xxx xxx
Min – Max xx-xx xx-xx xx-xx
Gender
Male xxx xxx xxx
Female xxx xxx xxx
Race
Caucasian xxx xxx xxx
Black xxx xxx xxx
Others xxx xxx xxxAsian xxx xxx xxx
Native Hawaiian or other Pacific Islander
xxx xxx xxx
Post text (e.g. explanation of p-values)
“Jazz it up” in style!!
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 13/24
Current state of the report
Cel l wid th
Bold
Indent
Indent
Indent
Indent
Indent
Indent
IndentIndent
Indent
Indent
Indent
Center
Other stuff: All those borders; font; post-text
“Jazz it up” in style!!
See documentation
Treatment Group
Placebo Treatment A Treatment B
Age
n 6 7 6
Mean (SD) 13.2 (1.72) 13.0 (1.29) 13.8 (1.60)
Median 13 12 15
Min - Max 11 - 16 12 - 15 11 - 15
Gender
Male 4 (66.7%) 4 (57.1%) 2 (33.3%)
Female 2 (33.3%) 3 (42.9%) 4 (66.7%)
Race
Caucasian 4 (66.7%) 4 (57.1%) 4 (66.7%)
Black 1 (16.7%) 1 (14.3%) 1 (16.7%)
Other 1 (16.7%) 2 (28.6%) 1 (16.7%)
Asian 0 (0.0%) 1 (14.3%) 1 (16.7%)
Native Hawaiian or Pacific Islander 1 (16.7%) 1 (14.3%) 0 (0.0%)
Bold
BoldCenter Center
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 14/24
proc report nowindows data=temp.demo
style = [
frame=hsides
rules=groups
posttext=“Population subset”
font_face=“times new roman”font_size=8 pt]
“Jazz it up” in style!!
style(header lines) = [
font_face=“times new roman”]
style(column) = [
font_face=“times new roman”
cellwidth=1.25 in
just=center] ;
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 15/24
column order1 order2 text treatment,values ;
define order1 / group noprint order=internal ;
define order2 / group noprint order=internal ;
define text / group " " ;
define treatment / across „Treatment Group‟ order = internal ;
define values / group " " ;
compute before order1 ;
line @1 " " ;
line @1 order1 header. ;
endcomp;
style = [cellwidth=2 in just=left] ;
/ style = [font_weight=bold] ;
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 16/24
proc report nowindows data=temp.demo
column order1 order2 text treatment,values ;define order1 / group noprint order=internal ;
define order2 / group noprint order=internal ;
define text / group „ „ ;
define treatment / across „Treatment Group‟
order = internal ;
define values / group „ „ ;
compute before order1 ;
line @1 „ „ ;
line @1 order1 head. ;
endcomp;
style = [frame=hsides rules=groups posttext=“Population subset”
font_face=“times new roman” font_size=8 pt
style(header lines) = [font_face=“times new roman”]
style(column) = [font_face=“times new roman” cellwidth=1.25 in just=center] ;
“Jazz it up” in style!!
style = [cellwidth=2 in just=left] ;
/ style = [font_weight=bold] ;
] just=left]
See demo2-rptstyle1.rtf
See demo3-rptstyle2.rtf
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 17/24
Destination language
• Insert “native” code
• Use [protectspecialchars=off] to keep ODS from protecting
text from interpretation by the program.
•Documentation
• (SAS RTF) From http://support.sas.com, on the left side,
click Focus Areas, Base SAS, ODS, SAS notes for ODS,
and under the ODS RTF section, click Concepts
• (Microsoft RTF) http://msdn2.microsoft.com/en-
us/library/aa140277(office.10).aspx
• (W3 HTML) www.w3schools.comSee documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 18/24
“Jazz it up” in style!!
define treatment / across „Treatment Group‟ order = internal format = treat. ;
define treatment / across „Treatment Group \brdrb\brdrs‟
style=[protectspecialchars=off] order = internal format = treat. ;
define text / group „ „ style = [cellwidth=3 in just=left pretext='\ql\li360 '
protectspecialchars=off ] ;
Before
After
See demo4-dest1
Note: 1 inch = 1,440 twips
Inserting a border underneath "Treatment Group"
Indenting the TEXT variable values
Left-align the post-text under the table without left-justifying the whole report
posttext = "\ql\li3450\ Population subset"
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 19/24
In-line Formatting
• Introduced in 8.2 as a way to style and format text “on the fly”
• Not PROC-specific
• Components
• Escape character
• Inline function• argument
• Documentation stinks!
• Check out http://support.sas.com/rnd/base/topics/expv8/inline82.html
• From http://support.sas.com, on the left side, click Focus Areas, Base
SAS, ODS, then scroll to the bottom under the Archive section. Click In-
Line Formatting For ODS in SAS 8.2
See documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 20/24
compute before order1 / style=[font_weight=bold];
line @1 „ „;
line @1 order1 head. ;
endcomp;
“Jazz it up” in style!!
define treatment / across „Treatment Group \brdrb\brdrs‟style=[protectspecialchars=off] order = internal ;
Before
After
Before
After
ODS escapechar = “^” ; /* global statement – can be executed anywhere */
define treatment / across „Treatment Group ^R/RTF”\brdrb\brdrs”‟ order = internal ;
compute before order1 / style=[font_weight=bold];
line @1 “^n” order1 head. ;
endcomp;
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 21/24
Conditional Styling
• COMPUTE Blocks allow certain data step statements, including IF-
THEN.
• CALL DEFINE sets attributes of report columns
See documentation
compute text ;
if order1 eq 3 and order2 in (4,5) thencall define(_col_,'style','style=[pretext="\ql\li720" font_style=italic]');
endcomp;
See demo5-con1.rtf
compute text ; /* just for illustration */
if order1 eq 3 and order2 eq 1 then
call define(_col_,'style','style=[pretext="\ql\li720" font_style=italic]');endcomp;
See demo6-con2.rtf
See documentation
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 22/24
Temporary Variables
In the DATA step
• Automatic variables (e.g. _ERROR_, _N_)
• Initialized by you
• Data set options (e.g. IN=, END=)
• BY statement (FIRST., LAST.)
IN PROC REPORT
• Initialized by you in a COMPUTE block
• Disappears after the procedure• Does not appear in a COLUMN or DEFINE
statement
• RETAINS ITS VALUE
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 23/24
proc report nowindows data=temp.demo
column order1 order2 text treatment,values ;
define order1 / group noprint order=internal ;
define order2 / group noprint order=internal ;
define text / group „ „style=[just=left cellwidth=2 in pretext='\ql\li360„ protectspecialchars=off];
define treatment / across „Treatment Group ̂ R/RTF”\brdrb\brdrs”‟order = internal ;
define values / group „ „ ;
compute before order1 / style = [font_weight=bold] ;
line @1 „^n‟ order1 head. ;endcomp;
style = [frame=hsides rules=groups posttext=“\ql\li3450 Population subset”
font_face=“times new roman” font_size=8 pt]
style(header lines) = [font_face=“times new roman”]
style(column) = [font_face=“times new roman” cellwidth=1.25 in just=center] ;
compute before order1 / style = [font_weight=bold] ;
temp = order1 ;line @1 „^n‟ order1 head. ;
endcomp;
compute text ;
if temp eq 3 and order2 in (4,5) then call define(_col_,'style','style=[pretext="\ql\li720"
font_style=italic]');
endcomp;
See demo7-con3.rtf
7/24/2019 Proc Report Tips and Tricks MM
http://slidepdf.com/reader/full/proc-report-tips-and-tricks-mm 24/24
• (SAS RTF) From http://support.sas.com, on the left side, click Focus Areas,
Base SAS, ODS, SAS notes for ODS, and under the ODS RTF section, click
Concepts
• (Microsoft RTF) http://msdn2.microsoft.com/en-
us/library/aa140277(office.10).aspx
• (W3 HTML) www.w3schools.com
• (SAS Online doc‟) From http://support.sas.com, click Product Documentation
then click on the version you want
• (SAS In-Line Formatting) From http://support.sas.com, on the left side, click
Focus Areas, Base SAS, ODS, then scroll to the bottom under the Archive
section. Click In-Line Formatting For ODS in SAS 8.2
Web Sites
Contact InformationName:
Phone Number:
E-Mail 1:
E-Mail 2:
Mike Molter
(919) 926-5710 (INC Research)
[email protected] (INC)
[email protected] (home)
Thank You
HASUG