In clinical industry, almost every companied would like to use PROC REPORT procedure to develop rtf output. This post will show you tricks that will be used in PROC REPORT.

­ID and PAGE option to fit many columns in more than one page

ID option specifies that item that you are defining is an ID variable. An ID variable and all columns to its left will appear at the left of every page of report. In our example, ID option was specified in variable COL1 and the COL1 appears in all pages.

PAGE option can insert a page break between a report. In our below sample code, we specified PAGE in variable COL7 (TRT6) and TRT6 was printed out in 2nd page.

#BYVAL title option to insert BY variable values

Value of BY variable can be added into a title or footnote through using #BYVAL option. This is very useful for developing tables that needs to be displayed by treatment group or parameter or visit. In our example, by variable GRP has two kinds of values: Treatment 1: xxxxxxxx and Treatment 2: xxxxxxxx. You can see that tables in first page and second page are for Treatment 1: xxxxxxxx while tables in last two pages are for Treatment 2: xxxxxxxx. This can be achieved by applying BY statement in PROC REPORT and #BYVAL title option.

PAGE option in BREAK statement to start a new page

COMPUTE BLOCK and LINE statement

Compute block and line statement can insert a blank line or a line of text before or after a set of observations. They can also insert something before or after a page.

SPAN header using two approaches

column pg ord seq col1 (“&ull Group1” col2-col3) m (“&ull Group2” col4 col5)

Columns defined by variables col2 and col3 share same span header – Group1 – while columns defined by variables col4 and col5 share same span header – Group2. Macro variable ull is to produce a black line under span header. This post also applies another way to define span header. Please see details for variables col7, col8, col9 and col10. Macro variables ul and tl are very important here.

Sample SAS code to create Template

Click here to hide/show code


proc template;
define style customtemp;
parent = Styles.RTF;

replace fonts /
‘TitleFont’ = (“Times New Roman”,10pt) /* Titles from TITLE statements */
‘TitleFont2’ = (“Times New Roman”,10pt) /* Procedure titles */
‘StrongFont’ = (“Times New Roman”,10pt,Bold)
‘EmphasisFont’ = (“Times New Roman”,10pt)
‘headingEmphasisFont’ = (“Times New Roman”,10pt,Bold)
‘headingFont’ = (“Times New Roman”,10pt,Bold) /* Table column and row headings */
‘docFont’ = (“Times New Roman”,10pt) /* Data in table cells */
‘tableFont’ = (“Times New Roman”,10pt)
‘footFont’ = (“Times New Roman”,10pt) /* Footnotes from FOOTNOTE statements */
‘FixedEmphasisFont’ = (“Times New Roman”,10pt)
‘FixedStrongFont’ = (“Times New Roman”,10pt,Bold)
‘FixedHeadingFont’ = (“Times New Roman”,10pt,Bold)
‘BatchFixedFont’ = (“Times New Roman”,10pt)
‘FixedFont’ = (“Times New Roman”,10pt)
;

replace color_list /
‘link’ = blue /* links */
‘bgH’ = _undef_ /* row and column header background */
‘fg’ = black /* text color */
‘bg’ = _undef_; /* page background color */

replace Body from Body /
topmargin = 1 in
bottommargin = 0.375 in
leftmargin = 1 in
rightmargin = 1 in
protectspecialchars = off
;

style Table from Table /
frame = hsides /* outside borders: void, box, above/below, vsides/hsides, lhs/rhs */
rules = groups /* internal borders: none, all, cols, rows, groups */
cellpadding = 1pt /* the space between table cell contents and the cell border */
cellspacing = 0pt /* the space between table cells, allows background to show */
borderwidth = 0.5pt /* the width of the borders and rules */
outputwidth = 100%
Background=_undef_
;

style UserText from UserText/
outputwidth = 100%
protectspecialchars = off
asis = on
just = left
;

replace NoteContent from NoteContent /
protectspecialchars = off
asis = on
just = left
;

style Footer from Footer /
asis = on
protectspecialchars = off
just = left
;

replace Header from Header /
protectspecialchars = off
asis = on
just = left
;

replace Data from Data /
protectspecialchars = off
asis = on
just = left
;

style systemtitle from systemtitle /
protectspecialchars=off;

style parskip /
fontsize = 0pt
;

end;
run;

SAS code to create sample dataset

Click here to hide/show code


proc format;
value txt
1 = “Sex, n (%)”
2 = “\li200 Female”
3 = “\li200 Male”
4 = “Country, n (%)”
5 = “\li200 China”
6 = “\li200 Australia”
7 = “\li200 New Zealand”
8 = “\li200 Korean, Republic of ”
9 = “\li200 Taiwan, province of China”
10 = “\li200 United of America”
;
quit;

data test01;
array col{12} $200. col1-col12;
do grpn = 1 to 2;
do i = 1 to 10;
pg = grpn;
if grpn =1 then grp = “Treatment 1: xxxxxxxx”;
else grp = “Treatment 2: xxxxxxxx”;
m = “”;
col1 = strip(put(i,txt.));
if i <= 3 then ord = 1;
else ord = 2;
seq = i;
do j = 2 to 12;
if i ne 1 then col{j} = “xx (xx.x)”;
end;
output;
end;
end;
run;

SAS code for PROC REPORT

Click here to hide/show code


%let ul = ^S={borderbottomcolor=black borderbottomwidth=1 borderrightcolor=white borderrightwidth=0.04 in}; /* underline for spanning headers*/
%let tl = ^S={borderrightcolor=white borderrightwidth=0.04 in}; /*create gaps between underlines of adjacent spanning headers*/
%let ull = \brdrb\brdrs\brdrw14\qc;

options nodate nobyline nonumber;
ods escapechar=”^”;
ods listing close;
ods tagsets.rtf file = “c:\demo.rtf” style = customtemp;

title1 j=c “Table 14.1 \line Demographics \line Safety Population”;
title2 j=c ” “;
title3 j=l “#byval(grp)”;

proc report data = test01 missing nowd split=”|”
style(column)={width=5% just = center}
style(header)={just = center};

by grpn grp;
column pg ord seq col1 (“&ull Group1” col2-col3) m (“&ull Group2” col4 col5) col6
(“&ul Group3” col7-col8) (“&ul Group4” col9-col10) col11-col12;

define pg / order noprint;
define ord / order noprint;
define seq / order noprint;
define col1 / display “” style(column)={width=15% just =left} id;
define col2 / display “TRT1|(N = xx)|n(%)”;
define col3 / display “TRT2|(N = xx)|n(%)”;
define m / display “” style(header)={width=0.1% just = center} style(column)={width=0.1%};
define col4 / display “TRT3|(N = xx)|n(%)”;
define col5 / display “TRT4|(N = xx)|n(%)”;
define col6 / display “TRT5|(N = xx)|n(%)”;
define col7 / display “TRT6|(N = xx)|n(%)” page;
define col8 / display “&tl TRT7|(N = xx)|n(%)”;
define col9 / display “TRT8|(N = xx)|n(%)”;
define col10 / display “TRT9|(N = xx)|n(%)”;
define col11 / display “TRT10|(N = xx)|n(%)”;
define col12 / display “TRT11|(N = xx)|n(%)”;

break after pg/page;

compute before ord;
line “”;
endcomp;

run;

ods tagsets.rtf close;
ods listing;

OUTPUT