Getting vector graphics output from PROC SGPLOT to PDF

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

When I create a graph and write it to PDF with ODS, the result looks fine in the sas EG report window, but the PDF output gets rasterized before setting DPI to PDF, so if you zoom in to PDF you can do. Also, if I don't define color / line styles, the PDF output will use different colors and styles (lines that were solid in the sas report window will be split in the PDF).

If I make the same diagram with PROC GPLOT it contains vectorized text and lines that don't look like garbage when zoomed in / out. In the meantime, there is no need to know about it. ”

Is there an option that I need to change? Do I need to set some flag? I've tried things like OPTIONS DEVICE=SVG

, and it doesn't seem to work. Setting a really high DPI is also not a good solution.

Sample code (but actually this happens in all 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;

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;


They bring up roughly equivalent plots in the sas EG result window (except SGPLOT looks better), but when they end up in pdf, SGPLOT rasterizes to an image and crashes to a PDF page, and GPLOT acts as fine vector graphics.

EDIT: See the solutions I posted below. I didn't find this well documented, but SAS 9.2 doesn't have very good PDF support. There are several workarounds that work for a 1-shot schedule, but the best solution is to simply upgrade to SAS 9.3.


source to share

3 answers

I finally solved it. There are several ways this kind of work works, and one way that actually works.

The "ideal" solution is up to SAS 9.3; SAS 9.2 cannot render SGPLON / SGPANEL graphics to vector PDF. Running the same code in SAS 9.3 creates perfect charts.

I found two more partial solutions:

1: In the enterprise manual, you can customize the display settings, and if everything goes right, you can print the SAS report window and use an Adobe PDF printer. This works fine, although the output sometimes looks very inactive.

2: ods latex file='file.tex' gout='/.../';

(set gout = to output directory). This gives, in unix 9.2, at least a TeX junk file that has no line breaks and does not seem to reference diagrams. It also creates a PostScript file for each plot! You can use this .ps file with Distiller (or TeX) to create decent vector diagrams. They print nicely, although I found the SAS 9.3 PDF to be viewed much better on screen than using the .ps from this method.



Here's 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;

ods pdf close;


The snippet imagefmt=pdf

tells SAS to generate the pdf image itself, instead of adding the png rasterization to the pdf report. This snippet should create a file called report.pdf in the c: \ temp directory. The image in it is scalable.

There is much more in the links below.

Image name and format management

Using PROC SGPLOT for fast, high quality charts



You may be able to improve the quality using Adobe print drivers. I found this example on the SAS website many years ago trying to solve a different problem, but it might work for your problem too.

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




All Articles