When I output PNG, the legend text can be fully displayed,
but when I output vector graphics, the last letter may be obscured,
and using the OUTERPAD options does not work
The text truncation is likely due to the ODS destination incorrectly calculating a bounding box for the text in the given font, essentially a bug.
A typical work around is to suffix your values with one or more hard space characters (hex A0).
If the legend value is coming from data:
length my_new_legend_var $50 ;
my_new_legend_var = cats(my_legend_var,"A0A0"x) ;
Can you share the legend statement ?
data final;
infile datalines truncover;
input subjid $ trt01pn trtdy;
datalines;
S07007 7 28.285714286
S03006 7 23.142857143
S03003 7 23.428571429
S11010 6 5.4285714286
S06005 6 11.857142857
;
run;
ods listing close;
ods rtf file="&_currentroot./f3.rtf" style=TLStyle nogtitle nogfootnote device=emf;
ods escapechar='@';
/*ods graphics/outputfmt=png;*/
options orientation=PORTRAIT;
%macro Swimmerplot;
proc template;
define statgraph Swimmer;
begingraph / designwidth=1080 designheight=1300 border=false backgroundcolor=white;
discreteattrmap name="trt01p" / ignorecase=true;
value "1" /markerattrs=GraphData1(color=Green symbol=circlefilled) lineattrs=GraphData1(color=Green pattern=solid ) fillattrs=GraphData1(color=Green);
value "2" /markerattrs=GraphData1(color=Bib symbol=circlefilled) lineattrs=GraphData1(color=Bib pattern=solid ) fillattrs=GraphData1(color=Bib);
value "3" /markerattrs=GraphData1(color=Bio symbol=circlefilled) lineattrs=GraphData1(color=Bio pattern=solid ) fillattrs=GraphData1(color=Bio);
value "4" /markerattrs=GraphData1(color=Brown symbol=circlefilled) lineattrs=GraphData1(color=Brown pattern=solid ) fillattrs=GraphData1(color=Brown);
value "5" /markerattrs=GraphData1(color=gray symbol=circlefilled) lineattrs=GraphData1(color=gray pattern=solid ) fillattrs=GraphData1(color=gray);
value "6" /markerattrs=GraphData1(color=Bigy symbol=circlefilled) lineattrs=GraphData1(color=Bigy pattern=solid ) fillattrs=GraphData1(color=Bigy);
value "7" /markerattrs=GraphData1(color=Pink symbol=circlefilled) lineattrs=GraphData1(color=Pink pattern=solid ) fillattrs=GraphData1(color=Pink);
value "8" /markerattrs=GraphData1(color=Bigb symbol=circlefilled) lineattrs=GraphData1(color=Bigb pattern=solid ) fillattrs=GraphData1(color=Bigb);
enddiscreteattrmap;
discreteattrvar attrvar=markers_trt01p var=trt01pn attrmap="trt01p";
legenditem type=marker name="L9" / LABELATTRS=(color=black family="Arial" size=10pt) markerattrs=(color=black symbol=TriangleRightFilled size=10pt) label="On Treatment";
legenditem type=marker name="L10" / LABELATTRS=(color=black family="Arial" size=10pt) markerattrs=(color=viro symbol=X size=10pt) label="Treatment Discontinued";
layout overlay / wallcolor=white walldisplay=none
xaxisopts=( label=("Time (Weeks)") labelattrs=(color=black family="Arial" size=10pt) tickvalueattrs=(family="Arial" size=10pt weight=normal )
linearopts=( tickvaluesequence=(start=0 end=&xend. increment=&xincrement.) tickvaluepriority=true))
yaxisopts=( display=(tickvalues ) tickvalueattrs=(family="Arial" size=10pt weight=normal ) discreteopts=( tickvaluefitpolicy=none));
barchart category=subjid response=trtdy / group=markers_trt01p datatransparency=0.3
display=(fill) stat=mean barlabel=false orient=horizontal barwidth=0.6 groupdisplay=stack clusterwidth=0.1;
discretelegend
'S7' 'L9' 'L10'
/
opaque=true border=false displayclipped=true across=1 order=columnmajor outerpad=auto valueattrs=(color=black family="Arial" size=10pt)
titleborder=false location=inside valign=bottom halign=right titleattrs=GraphValueText(color=black family="Arial" size=10pt);
endlayout;
endgraph;
end;
run;
%mend;
%Swimmerplot;
data _blank;
blank="";
run;
ods rtf startpage=no;
proc report data=_blank nowindows
style(report)={pretext="\outlinelevel2 f3 \fs1"}
;
column blank;
define blank/noprint;
run;
proc sgrender data=final template=Swimmer;
run;
ods graphics off;
ods rtf close;
ods results on;
ods listing close;
this is a test program, thanks
I did not get any problem.
data final; infile datalines truncover; input subjid $ trt01pn trtdy; datalines; S07007 7 28.285714286 S03006 7 23.142857143 S03003 7 23.428571429 S11010 6 5.4285714286 S06005 6 11.857142857 ; run; ods listing close; ods rtf file="c:\temp\f3.rtf" style=TLStyle nogtitle nogfootnote device=emf; ods escapechar='@'; /*ods graphics/outputfmt=png;*/ options orientation=PORTRAIT; %macro Swimmerplot; proc template; define statgraph Swimmer; begingraph / designwidth=1080 designheight=1300 border=false backgroundcolor=white; discreteattrmap name="trt01p" / ignorecase=true; value "1" /markerattrs=GraphData1(color=Green symbol=circlefilled) lineattrs=GraphData1(color=Green pattern=solid ) fillattrs=GraphData1(color=Green); value "2" /markerattrs=GraphData1(color=Bib symbol=circlefilled) lineattrs=GraphData1(color=Bib pattern=solid ) fillattrs=GraphData1(color=Bib); value "3" /markerattrs=GraphData1(color=Bio symbol=circlefilled) lineattrs=GraphData1(color=Bio pattern=solid ) fillattrs=GraphData1(color=Bio); value "4" /markerattrs=GraphData1(color=Brown symbol=circlefilled) lineattrs=GraphData1(color=Brown pattern=solid ) fillattrs=GraphData1(color=Brown); value "5" /markerattrs=GraphData1(color=gray symbol=circlefilled) lineattrs=GraphData1(color=gray pattern=solid ) fillattrs=GraphData1(color=gray); value "6" /markerattrs=GraphData1(color=Bigy symbol=circlefilled) lineattrs=GraphData1(color=Bigy pattern=solid ) fillattrs=GraphData1(color=Bigy); value "7" /markerattrs=GraphData1(color=Pink symbol=circlefilled) lineattrs=GraphData1(color=Pink pattern=solid ) fillattrs=GraphData1(color=Pink); value "8" /markerattrs=GraphData1(color=Bigb symbol=circlefilled) lineattrs=GraphData1(color=Bigb pattern=solid ) fillattrs=GraphData1(color=Bigb); enddiscreteattrmap; discreteattrvar attrvar=markers_trt01p var=trt01pn attrmap="trt01p"; legenditem type=marker name="L9" / LABELATTRS=(color=black family="Arial" size=10pt) markerattrs=(color=black symbol=TriangleRightFilled size=10pt) label="On Treatment"; legenditem type=marker name="L10" / LABELATTRS=(color=black family="Arial" size=10pt) markerattrs=(color=viro symbol=X size=10pt) label="Treatment Discontinuedxxxx yyyy"; layout overlay / wallcolor=white walldisplay=none xaxisopts=(label=("Time (Weeks)") labelattrs=(color=black family="Arial" size=10pt) tickvalueattrs=(family="Arial" size=10pt weight=normal ) linearopts=( tickvaluesequence=(start=0 end=30 increment=5) tickvaluepriority=true)) yaxisopts=( display=(tickvalues ) tickvalueattrs=(family="Arial" size=10pt weight=normal ) discreteopts=( tickvaluefitpolicy=none)); barchart category=subjid response=trtdy / group=markers_trt01p datatransparency=0.3 display=(fill) stat=mean barlabel=false orient=horizontal barwidth=0.6 groupdisplay=stack clusterwidth=0.1; discretelegend 'S7' 'L9' 'L10' / opaque=true border=false displayclipped=true across=1 order=columnmajor outerpad=auto valueattrs=(color=black family="Arial" size=10pt) titleborder=false location=inside valign=bottom halign=right titleattrs=GraphValueText(color=black family="Arial" size=10pt); endlayout; endgraph; end; run; %mend; %Swimmerplot; data _blank; blank=""; run; ods rtf startpage=no; proc report data=_blank nowindows style(report)={pretext="\outlinelevel2 f3 \fs1"} ; column blank; define blank/noprint; run; proc sgrender data=final template=Swimmer; run; ods graphics off; ods rtf close; ods results on; ods listing close;
😂strange
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.