BookmarkSubscribeRSS Feed
Fluorite | Level 6

I am creating a graph using proc sgrender in SAS 9.3. The graph is a forest plot created using a (slightly modified) v. of this macro:

I am outputting this (very tall) graph to pdf destination. When I use approach #1 below, the graph looks great. In approach #2, the graph looks bad. The default outputfmt in approach #2 is png, but the graph still looks the same (bad) if I set the outputfmt to pdf.

I would like to use approach #2, so I can send multiple outputs to pdf file (rather than one pdf file per graph with approach #1). But I haven't been able to figure out how to get the graph to look right using approach #2.

Thank you SAS community for any suggestions you may have.

Approach #1 -- pdf file can have one output only (but graph looks good)

ods graphics / reset outputfmt=pdf imagename="ex1" border=off;

ods listing image_dpi=300 gpath="C:\graphs";

proc sgrender data=_forest template=ForestMacro;


Approach #2 -- pdf file can have multiple outputs (but graph looks terrible)

ods graphics / reset border=off;

ods pdf file="C:\graphs\ex3.pdf" dpi=300;

proc sgrender data=_forest template=ForestMacro;



ods pdf close;


I'm confused.

outputfmt=pdf should give you a vector image, right?

did you try:

ods graphics/reset outputfmt=pdf border=off;

ods pdf file="..." ;

proc sgrender..;


proc sgrender..;



ods pdf close;

If that doesn't give you a bunch of nice looking vector images in the pdf, would check the log to see if it says anything about having given you an image output when you asked for a vector.


Check out the Boston Area SAS Users Group (BASUG) video archives:
Fluorite | Level 6

Thanks Quentin.

When I specify outputfmt=pdf in the 2nd approach the listing image output written to pdf looks great (exactly as in appoach #1, which makes sense since the code is now the same). But the ods pdf output still looks bad (exactly as before when I did not specify the outputfmt and the default outputfmt was png).

So, if in Approach 2 I changed ods graphics statement to:

ods graphics / reset outputfmt=pdf imagename="sg1" border=off;

then the sg1.pdf looks good but the ods pdf output (ex3.pdf) looks the same as before. I do not get any messages about vector v. image output in the log. I know that vector graphics are not supported for all types of graphs but I don't know if that is an issue here. I am mystified why the listing pdf output is good (when the outputfmt=pdf) but the ods pdf output is not.

Meteorite | Level 14

The macro was tested for average test cases.  If you have a very tall graph, you may need to customize the macro.  Break your data into smaller pieces.  If you are running SAS 9.2, you will get an image embedded in the PDF.  With SAS 9.3 onwards, you will get a real vector graph in most cases.

Fluorite | Level 6

I can appreciate that the macro -- which is awesome, btw -- might have issues outside 'average' applications. I overrode the 100 obs, for example. But in fact the macro output was perfect  (exactly what I wanted) -- but only in the listing image output written to pdf.

I'm confused why the listing output written to pdf (#1) and the ods output written to pdf (#2) look so different -- and wondering if there's anything I can do to make #2 look like #1 (aside from a piecemeal approach creating a series of graphs to try and approx for #2 what I can achieve with a single graph for #1). The only drawback for me with #1 is that I need a pdf file for each image I create; but, o/w, the graph is rendered well.

Meteorite | Level 14

It is always easier to help if the full program (with data) is attached so we can run it and debug.  The styles for PDF and Listing are different.  Also, the macro tries to compute a size for the output graph, which is set in the BEGINGRAPH statement.  My guess is the PDF is trying to squeeze it on one page.  Not sure how PDF deals with this.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3 in conversation