In case you don't feel comfortable looking at the attachments, you can copy, paste, and run the code you see below. It'll spit out the same file. I'm trying to place the table and graph on the same line and make sure they're left justified. Seems that the OPTIONS NOCENTER didn't work with the bar chart.
The closest I tried is adding the ODS RTF COLUMNS=2 option right before PROC REPORT and ODS RTF COLUMNS=1 after PROC SGPLOT. Even so, it puts everything in 2 columns when I prefer just the visuals and you'll see that bar chart center justified in the second column.
Any idea how I can place the table and bar chart 1 space apart on the same line? I know I can just simply do it myself manually in Word, but how would I do it via SAS especially if I was to automate a mass file production?
%let outsy=E:\Users\Pete\Desktop\qb;
data qbdats;
input QB $ completed passes;
datalines;
Brett 23 35
Tom 21 29
Peyton 34 41
Eli 32 37
Aaron 26 38
;
run;
/* at this point main this is basically adding the _type_
variable but would be appropriate if your data was
per game or similar
A GROUP variable creates a stacked barchart with
separate colors for each level. If you only have
on value for a group it stands out as desired.
*/
proc summary data=qbdats;
class QB;
var completed passes;
output out=qbsums sum=;
run;
data qb_pass_rate;
set qbsums;
completion_rate = completed/passes ;
if missing(QB) then QB='Total';
run;
data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is BARTYPE */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */
input id $ value fillcolor $;
datalines;
_type_ 0 green
_type_ 1 blue
;
run;
%let defaulttablefont=font_face=Calibri fontsize=10pt;
ods noresults escapechar='^';
%let bc=cxD3DFEE;
%let bw=1;
%let breaklinesandwich=borderbottomcolor=&bc borderbottomwidth=&bw.pt bordertopcolor=&bc bordertopwidth=&bw.pt;
%let boxy=borderwidth=&bw.pt bordercolor=&bc;
%let titlestyle=font_face=Calibri fontsize=12pt fontweight=bold background=cxD3DFEE;
ods path sasuser.templat(UPDATE)
mylib.templat (READ)
sashelp.tmplmst(READ);
proc template;
define style styles.test1;
parent=styles.printer;
style Body from Document /
marginbottom = 0.5in
margintop = 0.5in
marginright = 0.5in
marginleft = 0.5in;
end;
run;
ods rtf file="&outsy\qb_stats.rtf" style=styles.test1 startpage=never;
options nocenter;
ods rtf text="^{newline}^{style[font_face=Calibri fontsize=11pt &breaklinesandwich]This report provides a
summary of data collected for the QB passes in football. The task was issued to Pete in XXX game(s).}^{newline}";
ods rtf text="^{newline}";
/*ods rtf columns=2;*/
PROC REPORT DATA = qb_pass_rate(where=(qb^='Total')) MISSING nowd
STYLE(REPORT)=[BACKGROUND=WHITE ASIS=ON just=l frame=box &defaulttablefont]
style(column)=[&defaulttablefont]
style(header)=[background=white &defaulttablefont fontweight=bold borderbottomcolor=black borderbottomwidth=3]
;
COLUMN QB Completed passes pctComp;
COMPUTE qb;
COUNT+1;
IF (MOD(COUNT,2)) THEN CALL DEFINE (_ROW_, 'STYLE', 'STYLE=[BACKGROUND=cxD3DFEE]');
IF _BREAK_="_RBREAK_" THEN DO;
qb = 'Total';
CALL DEFINE (_ROW_, 'STYLE', "STYLE=[BACKGROUND=cxD3DFEE fontweight=bold bordertopcolor=black bordertopwidth=3]");
end;
ENDCOMP;
DEFINE qb / "QB" ORDER=data center;
DEFINE Completed / "# caught" center format=comma.;
DEFINE passes / "# of passes" center format=comma.;
define pctComp / "Pass Completion Rate (%)" computed center format=percent8.2;
compute pctComp;
pctComp=completed.sum/passes.sum;
endcomp;
RBREAK AFTER / SUMMARIZE;
RUN;
ods graphics on / width=4in height=3in;
proc sgplot data= qb_pass_rate dattrmap=attrmap noautolegend;
title; footnote;
xaxis label = 'QB' labelattrs=(Family=Calibri Size=10 Weight=bold)
type=discrete discreteorder=data display=(noticks);
yaxis label='Pass Completion Rate (%)' labelattrs=(Family=Calibri Size=10 Weight=bold)
tickvalueformat=percent6. grid gridattrs=(color=gray pattern=shortdash thickness=1);
vbar qb / response= completion_rate group=_type_ attrid=_type_ datalabel datalabelattrs=(weight=bold);
format completion_rate percent8.2;
run;
/*ods rtf columns=1;*/
ods rtf close;
ods _all_ close;
With ODS LAYOUT you can create regions that are side by side with PDF, not RTF, output. I don't use PDF much so can't point to anything except the examples in the online help.
Looks like pulling a 2-column for only a part of page rather than whole is doable through ODS RTF. However, I'm lost on where would be good spots to wedge in ODS RTF COLUMNS=1 and ODS RTF COLUMNS=2 to put together only the table and chart side-to-side. Any idea?
%let outsy=E:\Users\pete\Desktop\qb;
data qbdats;
input QB $ completed passes;
datalines;
Brett 23 35
Tom 21 29
Peyton 34 41
Eli 32 37
Aaron 26 38
;
run;
/* at this point main this is basically adding the _type_
variable but would be appropriate if your data was
per game or similar
A GROUP variable creates a stacked barchart with
separate colors for each level. If you only have
on value for a group it stands out as desired.
*/
proc summary data=qbdats;
class QB;
var completed passes;
output out=qbsums sum=;
run;
data qb_pass_rate;
set qbsums;
completion_rate = completed/passes ;
if missing(QB) then QB='Total';
run;
data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is BARTYPE */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */
input id $ value fillcolor $;
datalines;
_type_ 0 green
_type_ 1 blue
;
run;
%let defaulttablefont=font_face=Calibri fontsize=10pt;
ods noresults escapechar='^';
%let bc=cx7BA0CD;
%let bw=1;
%let breaklinesandwich=borderbottomcolor=&bc borderbottomwidth=&bw.pt bordertopcolor=&bc bordertopwidth=&bw.pt;
/*%let boxy=borderwidth=&bw.pt bordercolor=&bc;*/
%let titlestyle=borderwidth=&bw.pt bordercolor=&bc font_face=Calibri fontsize=12pt fontweight=bold background=cxD3DFEE;
ods path sasuser.templat(UPDATE)
mylib.templat (READ)
sashelp.tmplmst(READ);
proc template;
define style styles.test1;
parent=styles.rtf;
style fonts /
'TitleFont' = ("Arial",16pt)
'TitleFont2' = ("Arial",16pt)
'StrongFont' = ("<MTserif>, Times Roman",10pt,bold)
'EmphasisFont' = ("Calibri",10pt,bold)
'FixedEmphasisFont' = ("<MTmonospace>, Courier",9pt,italic)
'FixedStrongFont' = ("<MTmonospace>, Courier",9pt,bold)
'BatchFixedFont' = ("SAS Monospace, <MTmonospace>, Courier",6.7pt)
'FixedFont' = ("<MTmonospace>, Courier",9pt)
'headingFont' = ("<MTserif>, Times Roman",11pt,bold)
'docFont'=("Calibri",10pt)
;
style GraphFonts /
'NodeDetailFont' = ("<MTserif>, <serif>",7pt)
'NodeInputLabelFont' = ("<MTserif>, <serif>",9pt)
'NodeLabelFont' = ("<MTserif>, <serif>",9pt)
'NodeTitleFont' = ("<MTserif>, <serif>",9pt)
'GraphDataFont' = ("Calibri",10pt,bold)
'GraphUnicodeFont' = ("<MTserif-unicode>",9pt)
'GraphValueFont' = ("Calibri",16pt)
'GraphLabel2Font' = ("Calibri",10pt)
'GraphLabelFont' = ("Calibri",10pt,bold)
'GraphFootnoteFont' = ("<MTserif>, <serif>",10pt)
'GraphTitleFont' = ("<MTserif>, <serif>",11pt,bold)
'GraphTitle1Font' = ("<MTserif>, <serif>",14pt,bold)
'GraphAnnoFont' = ("Calibri",10pt)
;
/* class TitlesAndFooters /*/
/* font = Fonts('TitleFont2')*/
/* backgroundcolor = colors('systitlebg')*/
/* color = colors('systitlefg')*/
/* ;*/
style systemtitle from TitlesAndFooters /
just=left
vjust=bottom
;
style Body from Document /
marginbottom = 0.5in
margintop = 1in
marginright = 1in
marginleft = 1in;
style Table from Output /
/* bordercollapse = separate*/
rules = ALL
cellpadding = 1pt
bordercolor=cx7BA0CD
borderwidth=2pt
borderstyle = solid
/* font=fonts('docFont')*/
;
style header from table /
just=center
vjust=middle
fontweight=bold
background=white
borderbottomcolor=cx7BA0CD
borderbottomwidth=2pt
paddingleft=5pt
paddingright=5pt
;
class cell /
paddingleft=5pt
paddingright=5pt
;
class graph /
just=left;
end;
run;
ods rtf file="&outsy\qb_stats.rtf" style=styles.test1 startpage=no;
options nocenter nonumber nodate;
title "HEADER TEST";
ods rtf text="^{newline}^{style[font_face=Calibri fontsize=11pt &breaklinesandwich]This report provides a
summary of data collected for the QB passes in football. The task was issued to Pete in XXX game(s).}^{newline}";
ods rtf text="^{newline}";
ods rtf text="^S={outputwidth=100% &titlestyle}TEST TITLE 1: QB STATS";
ods rtf columns=1;
ods rtf columns=2;
PROC REPORT DATA = qb_pass_rate(where=(qb^='Total')) MISSING nowd
STYLE(REPORT)=[BACKGROUND=WHITE ASIS=ON just=l frame=box]
/* style(column)=[&defaulttablefont]*/
style(summary)=[bordertopcolor=cx7BA0CD bordertopwidth=2pt]
;
COLUMN QB Completed passes pctComp;
COMPUTE qb;
COUNT+1;
IF (MOD(COUNT,2)) THEN CALL DEFINE (_ROW_, 'STYLE', 'STYLE=[BACKGROUND=cxD3DFEE]');
IF _BREAK_="_RBREAK_" THEN qb = 'Total';
ENDCOMP;
DEFINE qb / "QB" ORDER=data;
DEFINE Completed / "# caught" center format=comma.;
DEFINE passes / "# of passes" center format=comma.;
define pctComp / "Pass Completion Rate (%)" computed center format=percent8.2;
compute pctComp;
pctComp=completed.sum/passes.sum;
endcomp;
RBREAK AFTER / SUMMARIZE;
RUN;
ods rtf columns=1;
ods graphics on / width=3.5in height=2.5in;
/*ods graphics / reset=index imagename='barchart1' imagefmt=jpg;*/
/*ods graphics / width=3.5in height=2.5in reset=index imagename='barchart1' imagefmt=jpg;*/
/*ods listing gpath="&outsy";*/
proc sgplot data= qb_pass_rate dattrmap=attrmap noautolegend;
title; footnote;
xaxis label = 'QB'
/* labelattrs=(Family=Calibri Size=10 Weight=bold)*/
type=discrete discreteorder=data display=(noticks);
yaxis label='Pass Completion Rate (%)'
/* labelattrs=(Family=Calibri Size=10 Weight=bold)*/
tickvalueformat=percent6. grid gridattrs=(color=gray pattern=solid thickness=1);
vbar qb / response= completion_rate group=_type_ attrid=_type_ datalabel;* datalabelattrs=(weight=bold);
format completion_rate percent8.2;
run;
ods rtf text="^S={outputwidth=100% &titlestyle}TEST TITLE 2: BLABLABLA";
ods rtf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla1}";
ods rtf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla2}";
ods rtf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla3}";
/*ods graphics off;*/
/*ods listing close;*/
/*ods rtf columns=1;*/
ods rtf close;
ods _all_ close;
When you refer to the attached RTF, I sort of managed to make a selective 2-column section.
I notice it's much more easily achievable through ODS PDF and ODS LAYOUT mix. A hiccup or two remaining is I'm seeing white horizontal streaks in my table. The other is I had to wedge in ods pdf text="^{newline 5}"; to ensure proper space between end of ODS LAYOUT and next section in the PDF. What can be done to at least eliminate those streaks?
%let outsy=E:\Users\pete\Desktop\qb;
data qbdats;
input QB $ completed passes;
datalines;
Brett 23 35
Tom 21 29
Peyton 34 41
Eli 32 37
Aaron 26 38
;
run;
/* at this point main this is basically adding the _type_
variable but would be appropriate if your data was
per game or similar
A GROUP variable creates a stacked barchart with
separate colors for each level. If you only have
on value for a group it stands out as desired.
*/
proc summary data=qbdats;
class QB;
var completed passes;
output out=qbsums sum=;
run;
data qb_pass_rate;
set qbsums;
completion_rate = completed/passes ;
if missing(QB) then QB='Total';
run;
data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is BARTYPE */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */
input id $ value fillcolor $;
datalines;
_type_ 0 green
_type_ 1 blue
;
run;
%let defaulttablefont=font_face=Calibri fontsize=10pt;
ods noresults escapechar='^';
/* Centralized border styles -Peter Ahn, 7/28/2017 */
%let bc=cx7BA0CD;
%let bw=0.5;
%let pdftextframe=borderleftcolor=&bc borderleftwidth=&bw.pt borderrightcolor=&bc borderrightwidth=&bw.pt
bordertopcolor=&bc bordertopwidth=&bw.pt borderbottomcolor=&bc borderbottomwidth=&bw.pt;
/*%let titlestyle=bordercolor=&bc borderwidth=&bw.pt font_face=Calibri fontsize=12pt fontweight=bold background=cxD3DFEE;*/
%let titlestyle=&pdftextframe font_face=Calibri fontsize=12pt fontweight=bold background=cxD3DFEE;
ods path sasuser.templat(UPDATE)
mylib.templat (READ)
sashelp.tmplmst(READ);
proc template;
define style styles.test1;
parent=styles.printer;
style fonts /
'TitleFont' = ("Arial",16pt)
'TitleFont2' = ("Arial",16pt)
'StrongFont' = ("<MTserif>, Times Roman",10pt,bold)
'EmphasisFont' = ("Calibri",10pt,bold)
'FixedEmphasisFont' = ("<MTmonospace>, Courier",9pt,italic)
'FixedStrongFont' = ("<MTmonospace>, Courier",9pt,bold)
'BatchFixedFont' = ("SAS Monospace, <MTmonospace>, Courier",6.7pt)
'FixedFont' = ("<MTmonospace>, Courier",9pt)
'headingFont' = ("<MTserif>, Times Roman",11pt,bold)
'docFont'=("Calibri",10pt)
;
style GraphFonts /
'NodeDetailFont' = ("Calibri",10pt)
'NodeInputLabelFont' = ("Calibri",10pt)
'NodeLabelFont' = ("Calibri",10pt)
'NodeTitleFont' = ("Calibri",10pt)
'GraphDataFont' = ("Calibri",8pt,bold)
'GraphUnicodeFont' = ("Calibri",10pt)
'GraphValueFont' = ("Calibri",10pt)
'GraphLabel2Font' = ("Calibri",10pt)
'GraphLabelFont' = ("Calibri",12pt,bold)
'GraphFootnoteFont' = ("Calibri",10pt)
'GraphTitleFont' = ("Calibri",10pt,bold)
'GraphTitle1Font' = ("Calibri",10pt,bold)
'GraphAnnoFont' = ("Calibri",10pt)
;
/* class TitlesAndFooters /*/
/* font = Fonts('TitleFont2')*/
/* backgroundcolor = colors('systitlebg')*/
/* color = colors('systitlefg')*/
/* ;*/
style systemtitle from TitlesAndFooters /
just=left
vjust=bottom
;
style Body from Document /
marginbottom = 0.5in
margintop = 0.6in
marginright = 0.6in
marginleft = 0.6in;
style Table from Output /
bordercollapse = collapse
rules = ALL
cellpadding = 1pt
cellspacing=0
borderspacing=0
bordercolor=cx7BA0CD
borderwidth=1pt
borderstyle = solid
/* font=fonts('docFont')*/
;
style header from table /
just=left
vjust=middle
fontweight=bold
background=white
borderbottomcolor=cx7BA0CD
borderbottomwidth=1pt
paddingleft=4pt
paddingright=4pt
paddingtop=2pt
paddingbottom=2pt
;
class cell /
paddingleft=4pt
paddingright=4pt
;
class graph /
just=left;
end;
run;
ods pdf file="&outsy\qb_stats.pdf" style=styles.test1 startpage=no;
options nocenter nonumber nodate;
title "HEADER TEST";
ods pdf text="^S={font_face=Calibri fontsize=11pt borderbottomcolor=cx7BA0CD borderbottomwidth=1pt bordertopcolor=cx7BA0CD bordertopwidth=1pt}
^{newline}This report provides a summary of data collected for the QB passes in football. The task was issued to Pete in XXX game(s).^{newline 2}";
ods pdf text="^{newline}";
ods pdf text="^S={outputwidth=100% &titlestyle}TEST TITLE 1: QB STATS";
ods layout gridded columns=2;
ods region;
ods graphics on / width=3.5in height=2.5in;
PROC REPORT DATA = qb_pass_rate(where=(qb^='Total')) MISSING nowd
STYLE(REPORT)=[BACKGROUND=WHITE ASIS=ON just=l frame=box]
/* style(column)=[&defaulttablefont]*/
style(summary)=[bordertopcolor=cx7BA0CD bordertopwidth=2pt]
;
COLUMN QB Completed passes pctComp;
COMPUTE qb;
COUNT+1;
IF (MOD(COUNT,2)) THEN CALL DEFINE (_ROW_, 'STYLE', 'STYLE=[BACKGROUND=cxD3DFEE]');
IF _BREAK_="_RBREAK_" THEN qb = 'Total';
ENDCOMP;
DEFINE qb / "QB" ORDER=data;
DEFINE Completed / "# caught" center format=comma.;
DEFINE passes / "# of passes" center format=comma.;
define pctComp / "Pass Completion Rate (%)" computed center format=percent8.2;
compute pctComp;
pctComp=completed.sum/passes.sum;
endcomp;
RBREAK AFTER / SUMMARIZE;
RUN;
ods region;
ods graphics on / width=3.5in height=2.5in;
proc sgplot data= qb_pass_rate dattrmap=attrmap noautolegend;
title; footnote;
xaxis label = 'QB'
/* labelattrs=(Family=Calibri Size=10 Weight=bold)*/
type=discrete discreteorder=data display=(noticks);
yaxis label='Pass Completion Rate (%)'
/* labelattrs=(Family=Calibri Size=10 Weight=bold)*/
tickvalueformat=percent6. grid gridattrs=(color=gray pattern=solid thickness=1);
vbar qb / response= completion_rate group=_type_ attrid=_type_ datalabel;* datalabelattrs=(weight=bold);
format completion_rate percent8.2;
run;
ods layout end;
ods pdf text="^{newline 5}";
ods pdf text="^S={outputwidth=100% &titlestyle}TEST TITLE 2: BLABLABLA";
ods pdf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla1}";
ods pdf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla2}";
ods pdf text="^{unicode '25cf'x} ^{style[font_face=Calibri fontsize=11pt]blablabla3}";
ods pdf close;
ods _all_ close;
I think the streaks in your output table might be due to cellpadding set to 0 in the table style of your Test1 style.
I ran your code and changed cellpadding to 3 pt. The white horizontal streaks disappeared.
Thank you so much ballardw and Suzanne 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.