BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lupitala
Calcite | Level 5

Hi!

I have a question regarding table outputs in SAS. I am working in automating reports by combining SAS and LATEX, for which I would prefer to have GIF, JEPG or PNG files instead of a PDF (since by creating a PDF I would need to "cut" the object in order to include in the LATEX only the object and not the complete page). Is there a possibility? I have been trying with goptions device=gif and with ods html without succeed (i.e. pls check the following codes).

/*the following code works with graphs but not with tables*/

filename grafout "xxx/table.gif";

ods _all_ close;

ods listing;

ods results off;

goptions reset=all device=gif gsfname=grafout gsfmode=replace;

/*some PROC REPORT*/

goptions reset=all;

/*The following code was something that I tryed but did not work!*/

filename grafout ""xxx/table.gif;

ods_all_close;

ods listing;

ods results off;

goptions device=gif;

ods listing close;

ods html file=grafout;

/*some PROC REPORT*/

ods html close;

ods listing;

I do not get any error message and a gif file is created without any table.

Can you pls help me to solve this issue?

Thanks in advance!

Lupita

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Your code would never work with tables. GOPTIONS and DEVICE= were only designed for SAS/GRAPH procedures, not for tabular procedures, such as PROC PRINT and PROC REPORT, etc. In the "old" days, there is a procedure called PROC GPRINT, that used to capture a table as an image, but not many folks use it anymore.

  As Tom suggests, if you use the ODS LATEX destination, a LaTeX source file is created with all the LaTeX markup code around your table. Assuming that you know how to include or combine LaTeX files, then you should be able to process the LaTeX tables the way you want.

  I understand that you need to somehow use a LaTeX compiler to compile your LaTeX document into the final form, so while the code below will make a LaTeX file, I do not have a Windows compiler to compile and/or display the source file. I can view the file in Notepad and see the LaTeX markup that's been created for the output.

cynthia

ods latex file='c:\temp\latex_out.txt';

  proc report data=sashelp.class nowd;

  run;

  

ods latex close;

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

Look into using the ODS output destination for LaTeX.

ods tagsets.latex ;

Cynthia_sas
SAS Super FREQ

Hi:

  Your code would never work with tables. GOPTIONS and DEVICE= were only designed for SAS/GRAPH procedures, not for tabular procedures, such as PROC PRINT and PROC REPORT, etc. In the "old" days, there is a procedure called PROC GPRINT, that used to capture a table as an image, but not many folks use it anymore.

  As Tom suggests, if you use the ODS LATEX destination, a LaTeX source file is created with all the LaTeX markup code around your table. Assuming that you know how to include or combine LaTeX files, then you should be able to process the LaTeX tables the way you want.

  I understand that you need to somehow use a LaTeX compiler to compile your LaTeX document into the final form, so while the code below will make a LaTeX file, I do not have a Windows compiler to compile and/or display the source file. I can view the file in Notepad and see the LaTeX markup that's been created for the output.

cynthia

ods latex file='c:\temp\latex_out.txt';

  proc report data=sashelp.class nowd;

  run;

  

ods latex close;

art297
Opal | Level 21

Now that Cynthia has mentioned it, proc gprint still works in 9.2.  E.g., try the following:

filename logfile 'c:\art\demo.log';

filename lisfile 'c:\art\demo.lis';

proc printto log=logfile print=lisfile new;

run;

proc report data=sashelp.class nowd;

run;

proc printto;

run;  

goptions device=jpeg gsfname=out ;

filename out 'c:\art\test.jpg' ;

proc gprint fileref=lisfile;

run;

David_SAS
SAS Employee

This worked for me:

ods printerpath=gif;

ods printer;

proc report data=sashelp.class nowd;

run;

ods printer close;

-- David Kelley, SASsasprt.gif

Cynthia_sas
SAS Super FREQ

David:

  Totally cool! I did not know you could use ODS PRINTER like that. I had to use OPTIONS for PRINTERPATH. Here's my log...

9    ods printer close;

NOTE: ODS PRINTER printed 1 page.

10   ods printerpath=gif;

         ------------

         1          22

                    76

WARNING 1-322: Assuming the symbol PRINTER was misspelled as printerpath.

ERROR 22-322: Syntax error, expecting one of the following: BODY, CSSSTYLE, FILE, LAYOUT,

              PRINTER, STYLE.

ERROR 76-322: Syntax error, statement will be ignored.

but I was able to open sasprt.gif with my default picture viewer application.

and, if I changed my ODS PRINTER; statement to ODS PRINTER file="C:\temp\myname.gif", then I was able to name the file something other than sasprt.gif as shown below and to direct it to a location other than my default directory location.

Pretty cool! I have now erased PROC GPRINT from permanent memory!

cynthia

12   ** use system option for printerpath;
13   options printerpath=gif;
14
15   ods printer;
NOTE: Writing ODS PRINTER output to DISK destination "C:\temp\output\sasprt.gif", printer "gif".
16
17   proc report data=sashelp.class nowd;
18
19   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.37 seconds
      cpu time            0.26 seconds


20
21   ods printer close;
NOTE: ODS PRINTER printed 1 page to C:\temp\output\sasprt.gif.

David_SAS
SAS Employee

Oops, I meant to say "options printerpath=gif;", as Cynthia discovered.

Works for PNG, SVG, what have you.

-- David Kelley, SAS

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
  • 6 replies
  • 12002 views
  • 6 likes
  • 5 in conversation