3
votes

Anyone have hints for getting clean PDF output from PROC SGPLOT (and similar functions like SGSCATTER)?

When I create a graph and write it to a PDF with ODS, the result looks fine in the sas EG report window but the PDF output gets rasterized to the DPI setting of the PDF so if you zoom into the PDF you can make out pixelation. Additionally, if I don't define colors/line styles, the output in the PDF will use different colors and styles (lines that were solid in the sas report window become dashed in the PDF).

If I make the same chart with PROC GPLOT, it comes with vectorized text and lines that don't look like junk when zoomed/printed.

Is there an option I need to change? Some flag I need to set? I've tried things like OPTIONS DEVICE=SVG and it doesn't seem to work. Setting a really high DPI isn't a very good solution either.

Code Example (but really, this happens on all of the SG* functions with any data/code):

options nonumber orientation=landscape;
ods pdf file='FILENAME.pdf' notoc;

proc sgplot data=shipped;
  series x=date y=weighted_price / group=type;
run;

proc gplot data=shipped;
  plot weighted_price*date=type;

symbol1   c=blue      i=join v=none w=1 l=1;
symbol2   c=red       i=join v=none w=1 l=1;
symbol3   c=brown     i=join v=none w=1 l=1;
run; ods pdf close;

These produce roughly equivalent graphs in the sas EG results window (except the SGPLOT looks nicer) but when they end up in the pdf, the SGPLOT is rasterized to an image and dropped onto the PDF page while the GPLOT comes out as a lovely vector chart.

EDIT: See solutions I posted below. I didn't find it to be well documented, but SAS 9.2 did not have very good PDF support. There are a couple of workarounds that are ok for a 1-off chart, but the best solution is to just upgrade to SAS 9.3.

3

3 Answers

4
votes

Here is a minimal example (the sgplot code comes from the sas docs):

ods graphics / imagefmt=pdf;
ods pdf file = 'c:\temp\report.pdf';

proc sgplot data=sashelp.class;
  scatter x=height y=weight;
  ellipse x=height y=weight;
run;

ods pdf close;

The imagefmt=pdf snippet tells SAS to create the image itself in pdf, instead of adding the rastering of a png to a pdf report. This snippet should produce a file named report.pdf in your c:\temp directory. The image in it is scalable.

There is much more in the links below.

Controlling the Image Name and Image Format

Using PROC SGPLOT for Quick High-Quality Graphs

0
votes

You might be able to improve the quality by using Adobe print drivers. I found this example on the SAS web site many years ago while trying to resolve a different issue, but it might work for your issue too.

options sysprint='Acrobat PDFWriter'
        'k:\ruzsa\users\pdf\pdfwriter.pdf';   /* <- Edit to the location of your driver. */
goptions reset=all device=winprtc;
0
votes

I have finally solved this. There are a few ways that sort of work, and one way that really works.

The "perfect" solution is upgrading to SAS 9.3; SAS 9.2 can't make the SGPLOT/SGPANEL charts into a vectored PDF. Running the same code in SAS 9.3 produces perfect looking charts.

I found two other partial solutions:

1: In enterprise guide, you can tweak the display settings and if you get everything right, you can print the SAS Report window and use an Adobe PDF printer. This works ok although the output sometimes looks very un-sas.

2: ods latex file='file.tex' gout='/.../'; (set gout= to your output directory). This produces, in unix 9.2 at least, a garbage TeX file that has no line breaks and doesn't seem to actually reference the charts. It also produces a PostScript file for every chart! You can use this .ps file with Distiller (or TeX) to create decent looking vector charts. They print nicely, although I found the SAS 9.3 PDF to look far better on screen than the .ps from this method.