Data visualization with SAS programming

sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

Reply
Occasional Contributor
Posts: 12

sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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:

http://support.sas.com/kb/43/addl/fusion_43855_1_forestmacro.sas.txt

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;

run;

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;

title;

run;

ods pdf close;

Trusted Advisor
Posts: 1,216

Re: sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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..;

run;

proc sgrender..;

run;

....

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.

HTH

Occasional Contributor
Posts: 12

Re: sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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.

SAS Super FREQ
Posts: 1,081

Re: sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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.

Occasional Contributor
Posts: 12

Re: sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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.

SAS Super FREQ
Posts: 1,081

Re: sending graphics output from PROC SGRENDER to PDF file in SAS 9.3

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.

Ask a Question
Discussion stats
  • 5 replies
  • 1267 views
  • 0 likes
  • 3 in conversation