07-26-2012 11:20 PM
I am trying to incorporate the SAS output into LaTeX. I've tried out a few of the LaTeX packages, but the style of the resulting tables is not very pleasant. Also SAS produces very nice looking output anyway, so I would like to use it directly instead. I can write my output to a pdf file and include this in LaTeX to get the desired result, but my problem is the paper size of the pdf output. In order to include in nicely into LaTeX, the size of the pdf is supposed to be the size of output(plus some margins for the border). Per default it is A4 which produces a huge border for small output. I can change the papersize in the options but would have to this specifically for every output. I also would not know the size of the output without some trial-and-error method first. Is there an option that automatically shrinks the papersize to the output size? Alternatively I could change the output format (to, say, ps) but the same problem exists either way.
Thanks for your help!
07-27-2012 11:06 AM
Have you tried using ODS LATEX destination instead of ODS PDF? I believe you can generate a LaTeX document, including the reference to your image and then you could use either your GOPTIONS (for SAS/GRAPH) or your ODS GRAPHICS statement (for ODS Graphics) to make the size of the image be the size you need.
I don't know of an option that would shrink the actual papersize to fit the output --because you set papersize in a global statement BEFORE running the graph procedure. I have always found the papersize and printer settings options to be trial and error, that require more than one pass to get right.
You might want to work with Tech Support on this issue. At least they could help you figure out whether ODS LATEX would work for you.
08-08-2012 04:22 AM
OP and Cyntia,
That's exactly the question I have after battling with SAS for 2 days.
A scalable vector graphics output to PDF with neat cropped margins where the graph or plot fits the PDF that can be included in latex document. SAS can do that in:
ods graphics / outputfmt=pdf imagename="BarChart";
proc sgplot data=sashelp.class;
vbar age / response=height stat=mean;
But after 12 hours I can't reproduce that for proc gplot for something like 2 time series plot below (sorry no reproducible data but it gives something like :
OPTIONS NODATE NONUMBER REPLACE;
goptions cback=white ymax=4in xmax=6in hsize=6in;
ods listing sge=on;
ods listing gpath="T:\My Docs\My SAS 9.2 Enterprise Guide Files\SCRAP" ;
ods graphics / imagefmt=PDF outputfmt=pdf imagename="BarChart";
ods printer dpi=300 nopdfnote pdf file="T:\My Docs\My SAS 9.2 Enterprise Guide Files\SCRAP\BarChart" ;
PROC GPLOT DATA = WORK.SORTTempTableSorted
PLOT equiv_dvol_total_ST * DATE_f equiv_dvol_total_ST_max * DATE_f /
HREF="01jan04"D TO "01jan11"D BY year
LABEL DATE_f="Time (days)"
equiv_dvol_total_ST="Equivalent Volume (average)"
equiv_dvol_total_ST_max="Equivalent Volume (max)";
End of task code.
I attached the resulting plot as .pdf, it's a graph plastered on the page and inserting that in latex inserts the whole page with the white space below.
08-08-2012 09:47 AM
A few thoughts:
1) ODS GRAPHICS (PROC SGPLOT, SGSCATTER & SGPANEL, Graph Template Language & automatic STAT procedure graphs) are controlled by an ODS GRAPHICS statement.
2) "classic" SAS/GRAPH procedures, such as GPLOT are -ONLY- impacted by GOPTIONS statements and global graph statements like AXIS, SYMBOL, etc. To have an impact on GPLOT, your DEVICE (PDF) would have to be set in a GOPTIONS statement.
Complicating factors are that you have LISTING turned on (with SGE, so do you want to post-edit your image?), but, SGE only works on ODS GRAPHICS, so I find that setting confusing since you are using GPLOT.
You have your size specifications in a GOPTIONS statement, which is good; but you have your output type or output format specified in an ODS GRAPHICS statement which would be lovely for SGPLOT, but not so useful for GPLOT -- they are different architectures, controlled by different mechanisms and different statements. Without any GOPTIONS setting for device, I believe that each destination will pick a device that they "like" best.
I'd recommend working with Tech Support, especially to clarify how to do what you want and which destination is best. And which graphics method (ODS GRAPHICS or SAS/GRAPH) gets you closer to what you want. Once you decide that, then you would either switch to all ODS GRAPHICS control methods or all GOPTIONS control methods.
08-08-2012 12:24 PM
Also, just noticed the DEV=SASEMF in the OPTIONS statement. I don't think that PDF likes SASEMF, so that is possibly hindering your output, too.
08-08-2012 02:05 PM
Thanks for the quick reply!
I was working in EG, so when it didn't output the vector graphics in PDF ( the graphs were rasterized and pixelized), for example when using Active Image for SAS V9, i had to start tinkering with the code produced by EG and searching for clues online.
How would you output that vector graphics pdf with page fit to graph using your 2nd method, the classic SAS/GRAPH proc gplot?
In STATA, I think it's a bit more straightforward, and graphs can be exported to vector pdf with page fit to graph automatically.
08-08-2012 05:56 PM
I think that for starters, you have to refer to the SVG instructions here:
They discuss using ODS PRINTER or ODS HTML -- and they have a GMAP example, a GCHART example and an SGPLOT example. They don't have a GPLOT example, explicitly, but you would follow the GMAP and GCHART example for GPLOT (and NOT the SGPLOT example).
Note the GOPTIONS statement that for the GCHART example, they use DEV=SVGT (I think they wanted some transparency since they were layering the SVG image onto the map image -- and, they use ODS PRINTER. I used regular DEV=SVG and PRINTERPATH=SVG and it seemed to work. I do not believe you will be able to do this point and click in EG. It seems to me that you will possibly have to turn off the EG device choices and possibly turn off the EG results as well, since you want to use ODS PRINTER and that is not one of the EG automatic choices. I see that SVG has its own options SVGHEIGHT and SVGWIDTH and although I used them in my code, and I can see my sizes specified in the XML file, but that was as far as I went with experimenting. I don't have a multi-image document and I didn't mess with very fancy legends or axes.
My understanding is that an SVG file is just an XML file -- which I can see if I look at the output file with Notepad, so I'm not sure what happens next. I can see the file in a browser, but not having any LaTeX experience, I don't know what goes where after I have the SVG file or how to insert it into a LaTeX document, especially since I don't have a LaTeX compiler on my machine. This example is the best I could come up with in limited time (very fake data with uneven intervals, but was OK with GPLOT). For more direction and the definitive answer to your question and/or more help with SVG, I'd recommend working with Tech Support.
do date = '01jan04'd to '01jan11'd by 7;
volavg = (ranuni(0) /10);
volmax = volavg*10;
** adjust volmax;
if volmax gt 1 then volmax = (volmax - 1) + .7;
proc print data=makedata (obs=100);
var date volavg volmax;
format date yymmdd8.;
ods _all_ close;
goptions reset=all hsize=6in vsize=4in dev=svg;
options printerpath=svg papersize=('6in','4in') nodate nonumber
ods printer file="c:\temp\make_svg_image.svg";
symbol i=join v=none c=blue;
symbol2 i=join v=none c=red;
axis1 label=none order=("01jan04"d to "01jan11"d by year);
axis2 label=none order=(0.0 to 1.0 by .1);
proc gplot data=makedata;
volmax*date / overlay
haxis = axis1
vaxis = axis2;
label date='Time(in days)'
volavg = 'Equivalent volume(average)'
volmax = 'Equivalent volume(max)';
format date yymmdd10.;
ods printer close;
08-09-2012 10:14 PM
Thanks a lot for the reply. I will look into the code over the weekend. Unfortunately, it seems SVG needs to be converted to PDf to be included in a .tex file. What I have adopted for now is this workflow EG and PROC Gplot -> Export to EMF -> Convert to PDF using Acrobat. I think the same can be used with SVG however I haven't tested it extensively. EMF and SVG are both vector graphics formats.
An interesting sidenote, I tried PROC SGPLOT on my data and it seems to produce those nice PDF graphs quite easily, however I can't use it in EG and I'm not very familiar with syntax to produce high quality academic graphs.