BookmarkSubscribeRSS Feed
scubamaggo
Calcite | Level 5

Hi,

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!

8 REPLIES 8
Cynthia_sas
SAS Super FREQ

Hi:

  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.

cynthia

Arsenio_Staer
Calcite | Level 5

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;

run;

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;

OPTIONS DEV=SASEMF;

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  /

OVERLAY

    VAXIS=AXIS1

    HAXIS=AXIS2

FRAME    SKIPMISS

    LHREF=1

    CHREF=CX969696

    HREF="01jan04"D TO "01jan11"D BY year

    LEGEND=LEGEND1

;

    LABEL DATE_f="Time (days)"

        equiv_dvol_total_ST="Equivalent Volume (average)"

        equiv_dvol_total_ST_max="Equivalent Volume (max)";

/* -------------------------------------------------------------------

  End of task code.

  ------------------------------------------------------------------- */

RUN; QUIT;

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.

Any idea how this can be solved? It's very close to that thread as well, , pretty much what happens when SAS meets academic work with vector graphics plots in latex.

Thank you!!

Arsenio

Cynthia_sas
SAS Super FREQ

Hi:

  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.

cynthia

Cynthia_sas
SAS Super FREQ

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.

cynthia

Arsenio_Staer
Calcite | Level 5

Cyntia,

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.

Thank you,

Arsenio

Cynthia_sas
SAS Super FREQ

Hi:

  I think that for starters, you have to refer to the SVG instructions here:

http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n0ezld96mjxs08n1lvoj...

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

http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n0ezld96mjxs08n1lvoj...

  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.

cynthia

  

data makedata;

  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;

     output;

  end;

run;

   

ods listing;

proc print data=makedata (obs=100);

  var date volavg volmax;

  format date yymmdd8.;

run;

  

ods _all_ close;

goptions reset=all hsize=6in vsize=4in dev=svg;

options printerpath=svg papersize=('6in','4in') nodate nonumber

        svgwidth=6in svgheight=4in;

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;

  plot volavg*date

       volmax*date / overlay

       frame

       legend

       haxis = axis1

       vaxis = axis2;

  label date='Time(in days)'

        volavg = 'Equivalent volume(average)'

        volmax = 'Equivalent volume(max)';

  format date yymmdd10.;

run;

quit;

ods printer close;

ods listing;


svg_file_in_ie_browser.pnglook_inside_svg_file.png
Arsenio_Staer
Calcite | Level 5

Dear Cyntia,

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.

Thank you,

Arsenio

DanH_sas
SAS Super FREQ

Actually, as long as your EG is using a 9.2 or greater SAS server, you can use the SG procedures in the code window.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 7175 views
  • 0 likes
  • 4 in conversation