Hi,
I have been successful in getting multiple tables exported to a single rtf file using ODS RTF and PROC REPORT. I am now trying to add a table of contents preceding the tables. I firstly tested the code with just a few tables. A TOC was generated with no problems. But Table 1 was placed right under the text that I specified with ODS PROCLABEL=. I then tried to remove the Table 1 using the code from Problem Note 31278: Table 1 node generated by PROC REPORT . The code worked. I then use the code in my script. Unfortunately, all the tables were split into one row per page. I think the problem is with the BREAK BEFORE. All my tables were displayed correctly (i.e. rows are not split) when I commented out the BREAK BEFORE statement but "Table 1" reappeared. I don't know how exactly the count variable works from the link.
Here is the code for my first table
/*---------------------------------------------------------------import data into SAS-------------------------------------------------------*/
data output.chapter2_tableSup&table_order.;
set &tData_uniVarBin_t1t2Count. ;
gap01='';
gap02='';
gap03='';
/*Create a variable to remove third node. This node iscontrolled by the BREAK BEFORE statement*/
report_3rd_node_breaker=1;
OBSNO=_N_;
run;
/*--------------------------------Add titles and footnotes----------------------------------------------------------*/
proc sort data= output.chapter2_tableSup&table_order.; by OBSNO report_3rd_node_breaker; run;
/*Get text for the 1st node of Table of Contents from a SAS macro variable
The first node is controlled with the ODS PROCLABEL statement.
*/
ODS PROCLABEL="&&chapter2_suppTableContent&table_order." ;
title4 J=L /*this is the table title*/
font='Times New Roman'
h=10pt
"&&chapter2_tableSuppTitle&table_order."
;
/*-----------------------------------------------------------Add table body-----------------------------------------------------------*/
proc report data=output.chapter2_tableSup&table_order.
contents="" /*Remove default 2nd node*/
nowd
split='|'
style(report)={width=100%
cellpadding=8px
font_face='Times New Roman'
font_size=10pt
borderwidth=1.5pt /* border thickness*/
background = TRANSPARENT}
style(header)={just=left
font_weight=bold
font_face='Times New Roman'
font_size=10pt
font_style=roman
protectspecialchars = OFF
background = TRANSPARENT}
style(column)={font_face='Times New Roman'
font_size=10pt
background = TRANSPARENT}
;
/*The COLUMN statement is used to list each report column*/
column varGroup OBSNO report_3rd_node_breaker depVar
gap01
("\brdrb\brdrdot\brdrw5\brdrcf1 MZ twin pairs (twin1, twin2)"
twinCPair_MZ_0_0 twinCPair_MZ_0_1 twinCPair_MZ_1_0 twinCPair_MZ_1_1 )
gap02
("\brdrb\brdrdot\brdrw5\brdrcf1 DZ twin pairs (twin1, twin2)"
twinCPair_DZ_0_0 twinCPair_DZ_0_1 twinCPair_DZ_1_0 twinCPair_DZ_1_1 )
gap03
sum_completePairs N_twinNonMissDepVar;
%def_group( cVar=varGroup /*variable name*/
,option=group /*specify option=order if to order data alphabeticall; = group if not to order data*/
,cName=Scale /*column header*/
,cWide=2 cm
,headerAlign=left /*alignment of header text in a column: left, center, right*/
,colAlign=left /*alignment of content in a column: left, center, right, d (decimal point) */
);
DEFINE OBSNO / ORDER NOPRINT;
DEFINE report_3rd_node_breaker / ORDER NOPRINT;
%def_display( cVar=depVar, cName=Diagnosis, cWide=3.5 cm, headerAlign=left, colAlign=left);
%def_display( cVar=twinCPair_MZ_0_0, cName=(0, 0), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_MZ_0_1, cName=(0, 1), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_MZ_1_0, cName=(1, 0), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_MZ_1_1, cName=(1, 1), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_DZ_0_0, cName=(0, 0), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_DZ_0_1, cName=(0, 1), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_DZ_1_0, cName=(1, 0), cWide=1 cm, headerAlign=right);
%def_display( cVar=twinCPair_DZ_1_1, cName=(1, 1), cWide=1 cm, headerAlign=right);
%def_display( cVar=sum_completePairs, cName=Total twin pairs, cWide=2.5 cm, headerAlign=right);
%def_display( cVar=N_twinNonMissDepVar, cName=Total twin individuals, cWide=1.5 cm, headerAlign=right);
/*Define all the gap variables*/
%def_display( cVar=gap01 ,cName= ,isFmt=N ,cFmt= ,cWide=0.2%);
%def_display( cVar=gap02 ,cName= ,isFmt=N ,cFmt= ,cWide=0.2%);
%def_display( cVar=gap03 ,cName= ,isFmt=N ,cFmt= ,cWide=0.2%);
/*Add horitzontal lines under every occurence of dependent variable column*/
compute varGroup;
if varGroup not="" then call define (_row_
,'style'
,'style={bordertopcolor=cyan bordertopwidth=1}');
endcomp;
compute after _page_ /style={just=l
font_size=10pt
font_face='Times New Roman'
borderbottomcolor=white
bordertopcolor=black};
endcomp;
break before report_3rd_node_breaker/ page contents=""; /*remove 3rd node*/
run;
Here is the code for creating the RTF file with the table
options missing = ' ' /*Specifies the character to print for missing numeric values.*/
center /*Specifies whether to center or left align SAS procedure output*/
nodate /*suppress default print of data time that this SAS program executed*/
nonumber /*suppress default print of page number on first title line of each page*/
orientation= landscape /*orientation=portrait */
;
TITLE1; TITLE2;
options bottommargin = 2 cm
topmargin = 2 cm
rightmargin = 2 cm
leftmargin = 2 cm
;
/*suppress the warning that a quoted string that exceeds 262 characters in length*/
options NOQUOTELENMAX ;
/*Store table title text CSV file in SAS macro variables and values*/
%include "&SAS_script_dir.\supp-table-title-text_to_SAS-macro-var.sas" ;
%include "&SAS_script_dir.\import_supplementary-table_table-of-contents.sas" ;
/* first tell ODS what character will be used as the ODS ESCAPECHAR character value*/
ods escapechar='~';
ods escapechar='^';
ods _all_ close;
ods rtf file= "&report_dir.\PhD-thesis_supplementary-tables_%sysfunc(date(), yymmdd10.).rtf"
style= Journal
contents
toc_data ;
; /*contents toc_data: show table of contents*/
/*Table S2-1*/
%let table_order = 1;
%let tData_uniVarBin_t1t2Count= output.manu1_count_twin_paris ;
%let tScript_uniVarBin_t1t2Count= Ch2_tabSup01_count-twin-pairs_binary-outcomes;
%include "&destin_script_dir.\&tScript_uniVarBin_t1t2Count..sas";
/*------------------ close ODS RTF device----------------------------------------------------*/
ods rtf close;
ods listing;
I printscreened the first two pages in my RTF file. The TOC looks right. But Table S2-1 (10 rows) is split into 10 pages with just one row per page.
I do have 10 rows in my SAS data set:
My table looks right after I commented out the BREAK BEFORE statement
*break before report_3rd_node_breaker/ page contents=""; /*remove 3rd node*/
But the unwanted Table1 appeared in my TOC:
I am looking forward to a solution/workaround. It would be great if someone can explain how the count variable works.
Cheers,
Chang
Thank you very much, Cynthia. Placing the dummy variable as the first thing in the COLUMN statement works.
I am having other problems with the TOC. Can you take a look?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.