BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JohnKeighley
Obsidian | Level 7

I am creating a graph for a publication and require the plot to be in vector format. I was happy with the plot in raster format. I have changed the sgplot output to create pdf's in vector format.

 

Issues:

1. Title is splitting

2. The x-axis labels look like they are left justified

 

Code :




data attrmap;
input @1 id $5. @7 Value $7. linecolor $ fillcolor $ MarkerColor $ ;
datalines;
Group Group 1 cxA5A5A5 cxA5A5A5 cxA5A5A5
Group Group 2 cxFFC000 cxFFC000 cxFFC000
Group Group 3 cxED7D31 cxED7D31 cxED7D31
Group Group 4 cx4472C4 cx4472C4 cx4472C4
;
RUN ;

 

%let dpi=350;
ods graphics on/ reset=all border=off width=8.0in outputfmt=svg;
ods pdf dpi=&dpi file="P:\IRB_STUDY6101-Data Staff\Possible Papers\Prostate 2021\Final draft\Plots\graph1.pdf";
title j=l h=14pt f="Arial" "Figure 1. This is an example showing how sas is splitting of a title when I do not want SAS to do this" ;
proc sgplot data=rates0 noautolegend noborder dattrmap=attrmap;
series x=yeardx y=rate_pred/group=Group lineattrs=(pattern=solid thickness=2.0px) name="line" attrid=Group;
scatter x=yeardx y=rate_pred/group=Group markerattrs=(symbol=diamondfilled size=7) attrid=Group;
scatter x=yeardx1 y=rate_pred1/group=Group markerattrs=(symbol=circlefilled color=black size=11);
xaxis values=(2004 to 2019 by 1) label="Year of visit" labelattrs=(Family='Arial' Size=12) valueattrs=(Size=10);
yaxis values=(0 to 220 by 20) label="Rate (per 100,000)" labelattrs=(Family='Arial' Size=12) valueattrs=(Size=10);
keylegend "line"/ location=inside position=topright linelength=.25in across=4 noborder valueattrs=(Family='Arial' Size=10);
footnote j=l h=10pt f="Arial/bold" "*black dot indicates a spline location";
run;
ods pdf close;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

I discussed this font behavior with some other colleagues. One suggested setting the SASPRTC graph driver might clear this up. Please add this line to the beginning of your program and see if it helps:

 

goptions device=SASPRTC;

 

Please let me know if that helps.

View solution in original post

24 REPLIES 24
Reeza
Super User
Try setting the linesize option?

ods pdf linesize 500;
DanH_sas
SAS Super FREQ

The example, as given, wraps for both raster and vector output. This happens because the font size is too large for the length of the title and the width of the graph. If I set the title font size to 10pt, it does not wrap for either raster or vector output.

JohnKeighley
Obsidian | Level 7

I have removed the outputfmt=svg from the ods graphics statement. It is understanding that all ods pdf documents are vector graphics.

 

The ods pdf linesize statement gives the following error:

 

1896 ods pdf linesize 150;
--------
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, (, ACCESSIBLE,
ACCESSIBLE_IDENTIFIER, ANCHOR, AUTHOR, BACKGROUND, BASE, BODY,
BOOKMARK, BOOKMARKGEN, BOOKMARKLIST, BOX_SIZING, CLOSE, COLOR,
COLUMNS, COMPRESS, CONTENTS, CSSSTYLE, DISPLAY, DOM, DPI, EXCLUDE,
FILE, FONTSCALE, GFOOTNOTE, GTITLE, HOST, KEYWORDS, NAMED_DEST,
NEWFILE, NOACCESSIBLE, NOACCESSIBLE_IDENTIFIER, NOBACKGROUND,
NOBOOKMARKGEN, NOBOOKMARKLIST, NOCOLOR, NOCONTENTS, NOGFOOTNOTE,
NOGTITLE, NOPDFNOTE, NOTOC, PACKAGE, PCL, PDF, PDFMARK, PDFNOTE,
PDFTOC, PRINTER, PS, SAS, SELECT, SGE, SHOW, STARTPAGE, STYLE,
SUBJECT, TEXT, TITLE, UNIFORM.
ERROR 202-322: The option or parameter is not recognized and will be ignored.

 

I'm not sure if linesize can be used with ods pdf.

I have changed the font size for the title to 8 which doesn't wrap but it's unacceptable. It's left justified instead of centered on plot. Wrapping starts when the title length aligns with the left side of the lengend.

I have attached the updated plot.



%let dpi=350;
ods graphics on/ reset=all border=off width=8.0in;
ods pdf linesize 150;
ods pdf dpi=&dpi file="G:\Data\Papers\Plots\graph1.pdf";
title j=c h=10pt f="Arial" "Figure 1. This is an example showing how sas is splitting of a title when I do not want SAS to do this" ;
proc sgplot data=rates0 noautolegend noborder dattrmap=attrmap;
series x=yeardx y=rate_pred/group=Group lineattrs=(pattern=solid thickness=2.0px) name="line" attrid=Group;
scatter x=yeardx y=rate_pred/group=Group markerattrs=(symbol=diamondfilled size=7) attrid=Group;
scatter x=yeardx1 y=rate_pred1/group=Group markerattrs=(symbol=circlefilled color=black size=11);
xaxis values=(2004 to 2019 by 1) label="Year of visit" labelattrs=(Family='Arial' Size=9);
yaxis values=(0 to 220 by 20) label="Rate (per 100,000)" labelattrs=(Family='Arial' Size=9);
keylegend "line"/ location=inside position=topright linelength=.25in across=4 noborder valueattrs=(Family='Arial' Size=8);
footnote j=l h=8pt f="Arial/bold" "*black dot indicates a spline location";
run;
ods pdf close;

PaigeMiller
Diamond | Level 26

LINESIZE is not an option for ODS PDF. (It only makes sense for text output, as far as I know)

--
Paige Miller
Reeza
Super User

@JohnKeighley my mistake! Linesize is not the correct fix here. It does look like the text is long enough to fit on a line at first glance, but I'd trust @DanH_sas testing over my non testing 🙂

 

 

JohnKeighley
Obsidian | Level 7

Paige

Thank you for your comment. From what I was seeing on-line I agree.

 

But, I've seen a lot of very good comments from Reeza so I'm not going to ignore a suggestion from her without testing or searching the documentation.

 

 

JohnKeighley
Obsidian | Level 7

I am running SAS 9.4 m7 64 bit on Windows 10

JohnKeighley
Obsidian | Level 7

Could you explain how I am mixing raster and vector? The output must be in vector format.

 

Thank you

 

Reeza
Super User

@JohnKeighley wrote:

Could you explain how I am mixing raster and vector? The output must be in vector format.

 

Thank you

 


I don't think Dan is saying you're mixing the two, but that the results are the same regardless of format type. The issue is the font size makes the text too long to be on a single line. You need to reduce the font size. 

 

 

DanH_sas
SAS Super FREQ

In your original post, you said that your graph looked fine with raster output, but not with vector output. To test that statement. I changed OUTPUTFMT=SVG to OUTPUTFMT=PNG on the ODS Graphics statement to have the raster output put into the PDF document. I got the same title-wrapping result using both PNG and SVG.

 

Since you said you have a different result with raster output, my theory now is that you first created the graph using ODS LISTING. One important point to note is that the default ODS styles are different between LISTING and PDF output, so that title might look different.

 

Again, changing the size of the title text in your TITLE statement should eliminate your wrapping problem (or shortening the length of the string). I assume the width of the graph must be at the current size due to publication requirements.

JohnKeighley
Obsidian | Level 7

Do you have any suggestions about the point where the title starts wrapping? If you notice the legend in the upper right corner takes about half of the width of the graph. The tittle starts wrapping when it aligns with the left edge of the legend.  The graph should be 4 inches wide I have been trying different widths to see if the splitting starts on a different word when changing the width. My graph is going to look very strange if I have a title that takes multiple lines but it's only half the width of the graph area and it's left justified. I have tried to center and right justify the title to no effect.

 

I am considering trying to use an ods text command to get the title since a title statement doesn't seem to work.

 

 

DanH_sas
SAS Super FREQ

I'm not seeing any of the behavior you describe. The legend is inside of the data area, so it has no impact on the title. For me, the title goes all of the way across the graph and wraps due to the length.

Can you run your test setting OUTPUTFMT=PNG for your PDF output and post it here? I want to make sure this is not a font issue. Thanks!

JohnKeighley
Obsidian | Level 7

I have changed the font and it fits on one line as long as the text is short enough to fit on the left half of the graph.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 24 replies
  • 1574 views
  • 8 likes
  • 4 in conversation