When generating a SAS table in format .rtf using proc report
, the column widths are not aligning to their specified widths. This is resulting in column headings taking up multiple lines, and a few values being truncated, which I want to avoid.
Using the data:
/* Insert data */
data aaa;
input cohort $ color $ sum $ pctn $;
datalines;
group_1 dark_yellow 2 12.500%
group_2 orange 6 37.500%
group_2 dark_green 8 50.000%
overall orange 6 30.000%
overall dark_green 8 42.250%
;
run;
And this code to generate a .rtf file with column widths of 7, 11, 16 and 30 respectively:
/* Output settings */
options nocenter nodate nonumber missing=' ' orientation=landscape linesize=116 pagesize=42; * page settings;
ods output close; * close ods output;
ods rtf close; * close ods rtf;
ods listing close; * close ods listing;
footnote "Table generated on %sysfunc(date(), worddatx.w.)"; * insert date below report;
ods rtf file = "C:\Astudies\Colors.rtf" bodytitle;
/* Generate table */
proc report data=aaa nowd split='~';
column cohort color sum pctn;
define cohort /order order=data width=7 left 'Cohort';
define color /display width=11 left 'Color';
define sum /display width=16 left 'Number of colors';
define pctn /display width=30 left 'Percentage of total colors (%)';
title 'Painting';
title2'Common colours per cohort';
run;
title; * remove any titles;
footnote; * remove any footnotes;
ods rtf close; * close ods rtf;
ods listing;
This results in this table. Columns 3-4 have titles spanning multiple lines (their lengths are 16 and 30 characters respectively). Column 2 has truncated values where the max character length (dark_yellow) should be 11.
You can set a PROC REPORT
column style width=
property in the DEFINE
column / STYLE=[]
option.
Sample Code
This example presumes 10" of landscape real estate, with relative (unitless) column widths of 7, 11, 16, and 30. A %SYSEVALF computation maps the relative widths to explicit inches to be used in the ODS RTF rendering.
proc report data=aaa nowd split='~'
;
column cohort color sum pctn;
define cohort /order order=data left 'Cohort' style=[width=%sysevalf(10 * 7 / (7+11+16+30))in];
define color /display left 'Color' style=[width=%sysevalf(10 * 11 / (7+11+16+30))in];
define sum /display left 'Number of colors' style=[width=%sysevalf(10 * 16 / (7+11+16+30))in];;
define pctn /display left 'Percentage of total colors (%)' style=[width=%sysevalf(10 * 30 / (7+11+16+30))in];;
title 'Painting';
title2'Common colours per cohort';
run;