Hi all,
I'm trying to put a space either at the right or the left of a column in proc report. Below is my code, the current table (dummy results and columns!) and the desired table (dummy columns and results!). I've tryed so many things either in the proc template or in proc report (spacing=, borderleftwidth=, borderspacing=...), either in the define statement or in the style options.
* Template for table outputs;
proc template;
define style tablestyle;
class table /
frame=box rules=groups;
style systemtitle /
fontfamily="times"
fontsize=2;
style systemfooter /
fontfamily="times"
fontsize=2;
end;
run;
ods listing close;
options orientation=portrait center;
ods rtf file="mytable.rtf" style=tablestyle;
ods rtf text="^S={font=('Times',12pt,bold)}&title4";
proc report data=final missing nowd headline center split="~"
style=[protectspecialchars=off font_face="&font" font_size=9 pt
posttext="\ql\li&pos &footnote1
\ql\li&pos &footnote2
\ql\li&pos &footnote3"]
style(header column)=[protectspecialchars=off font_face="&font" font_size=9 pt ];
column pageno ord v1 last_group_ind v2 gendern1-gendern4;
define pageno / order order=data noprint;
define ord / order order=data noprint;
define v1 / order "Category^{super a}" style(header)=[just=center fontweight=bold borderrightcolor=very light gray] style(column)=[asis=on just=left fontweight=bold cellwidth=1.4in ];
define last_group_ind / order noprint;
define v2 / display " " style(header)=[just=left fontweight=bold borderrightcolor=very light gray] style(column)=[asis=on just=left cellwidth=1.4in];
define gendern1 / display "Female" style(header)=[just=center fontweight=bold borderrightcolor=very light gray] style(column)=[just=right cellwidth=0.9in];
define gendern2 / display "Male" style(header)=[just=center fontweight=bold borderrightcolor=very light gray] style(column)=[just=right cellwidth=0.9in];
define gendern3 / display "No gender data" style(header)=[just=center fontweight=bold borderrightcolor=very light gray] style(column)=[just=right cellwidth=0.9in];
define gendern4 / display "Overall Total" style(header)=[just=center fontweight=bold] style(column)=[just=right cellwidth=0.9in borderspacing=];
break after pageno / page;
*** This is to get gray lines in the table ***;
compute pageno;
call define('_c1_','style', 'style=[bordertopcolor=black borderrightcolor=very light gray]');
endcomp;
compute ord;
call define('_c2_','style', 'style=[bordertopcolor=black borderrightcolor=very light gray]');
endcomp;
compute v1;
call define('_c3_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
endcomp;
compute last_group_ind;
call define('_c4_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
if last_group_ind ne "" then hold=last_group_ind;
endcomp;
compute v2;
call define('_c5_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
if hold = v2 then do;
call define(_row_,'style','style=[borderbottomwidth=1pt borderbottomcolor=black]');
end;
endcomp;
compute gendern1;
call define('_c6_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
endcomp;
compute gendern2;
call define('_c7_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
endcomp;
compute gendern3;
call define('_c8_','style', 'style=[bordertopcolor=very light gray borderrightcolor=very light gray]');
endcomp;
compute gendern4;
call define('_c9_','style', 'style=[bordertopcolor=very light gray]');
endcomp;
run;
ods rtf close;
ods listing;
Thank you!
Hi Cynthia,
Thank you so much for all these examples! With these, I now have exactly what I wanted in my rtf table.
Anne-Marie
Attached is the desired table
Reduce your example code the bareminimum.
Get rid of macro variables that we have no idea what they might be.
Use an example data set like SASHELP.CLASS or provide data in the form of a data set.
If your issue is that you want space between the displayed borders of the cells and the text try the CELLspacing= style override with a numeric value like 3 or 4 (likely not to need a very large value if it works).
See the difference in the output here:
proc report data=sashelp.class; columns sex height; run; proc report data=sashelp.class style(report)=[cellspacing=5] ; columns sex height; run;
Hi:
Other ways to do this involve fiddling without a STYLE template, using only WIDTH and JUST and margins within a cell or with CELLPADDING at the REPORT level, as shown below:
I did not alter the border style for the cells so you could see where the extra space was/was not added in each cell.
Here's the code for the above screen shot:
data fakedata;
length col1 $20 col2 $55 col3 col4 col5 $20;
infile datalines dlm=',' dsd;
input grpord ordvar col1 $ col2 $ col3 $ col4 $ col5 $;
return;
datalines;
1,1,"Total","N(row%)","2,000 (10.3)","2,000 (10.3)", "1,800 ( 9.2)"
2,1,"Site","Managed on site (non HCF)","1,000 ( 5.1)","500 ( 3.2)", "800 (10.1)"
2,2,"Site","Patient already in (enroute to) HCF when PCC called","1,000 ( 5.1)","500 ( 3.2)", "800 (10.1)"
2,3,"Site","Also Unknown","1,000 ( 5.1)","500 ( 3.2)", "800 (10.1)"
2,4,"Site","Other","1,000 ( 5.1)","500 ( 3.2)", "800 (10.1)"
2,5,"Site","Unknown","1,000 ( 5.1)","500 ( 3.2)", "800 (10.1)"
;
run;
ods rtf file='c:\temp\fakedata.rtf' startpage=no ;
proc report data=fakedata split='/';
column grpord col1 ordvar col2 col3 col4 col5;
define grpord / order noprint;
define col1 / order 'Category' style(column)={fontweight=bold};
define ordvar / order noprint;
define col2 / order order=data style(column)={width=2in};
define col3 / display '1 mo to <2 yr/Col3'
style(column)={just=r width=1.5in};
define col4 / display '2 yr to 13 yr/Col4' f=$char20.
style(column)={just=c width=1.5in};
define col5 / display ' 13 yr to 18 yr/Col5'
style(column)={rightmargin=.5in just=d width=1.5in};;
compute after / style={fontweight=bold just=l};
line 'Col3 uses just=r because otherwise, for char var just=l';
line 'Col4 uses just=c and width';
line 'Col5 uses rightmargin, just=d and width';
endcomp;
run;
proc report data=fakedata split='/'
style(report)={cellpadding=.15in}
style(column)={vjust=m just=d};
column grpord col1 ordvar col2 col3 col4 col5;
define grpord / order noprint;
define col1 / order 'Category' style(column)={fontweight=bold just=l};
define ordvar / order noprint;
define col2 / order order=data
style(column)={width=2in just=l};
define col3 / display '1 mo to <2 yr/Col3' ;
define col4 / display '2 yr to 13 yr/Col4';
define col5 / display ' 13 yr to 18 yr/Col5' ;
compute after / style={fontweight=bold just=l};
line 'report uses cellpadding= for all columns';
line 'also uses cellpadding, vjust=m and just=d for all columns';
line 'except uses just=l for COL1 and COL2 to offset just=d for numeric col';
endcomp;
run;
ods rtf close;
cynthia
Hi Cynthia,
Thank you so much for all these examples! With these, I now have exactly what I wanted in my rtf table.
Anne-Marie
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.