The SAS Output Delivery System and reporting techniques

How to print a SAS table as an image (gif, jpeg, png)

Accepted Solution Solved
Reply
N/A
Posts: 1
Accepted Solution

How to print a SAS table as an image (gif, jpeg, png)

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


Accepted Solutions
Solution
‎01-16-2012 04:37 PM
SAS Super FREQ
Posts: 8,742

Re: How to print a SAS table as an image (gif, jpeg, png)

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


All Replies
Super User
Super User
Posts: 6,498

How to print a SAS table as an image (gif, jpeg, png)

Look into using the ODS output destination for LaTeX.

ods tagsets.latex ;

Solution
‎01-16-2012 04:37 PM
SAS Super FREQ
Posts: 8,742

Re: How to print a SAS table as an image (gif, jpeg, png)

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;

PROC Star
Posts: 7,360

Re: How to print a SAS table as an image (gif, jpeg, png)

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;

SAS Employee
Posts: 174

Re: How to print a SAS table as an image (gif, jpeg, png)

This worked for me:

ods printerpath=gif;

ods printer;

proc report data=sashelp.class nowd;

run;

ods printer close;

-- David Kelley, SASsasprt.gif

SAS Super FREQ
Posts: 8,742

Re: How to print a SAS table as an image (gif, jpeg, png)

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.

SAS Employee
Posts: 174

Re: How to print a SAS table as an image (gif, jpeg, png)

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

Works for PNG, SVG, what have you.

-- David Kelley, SAS

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 3021 views
  • 6 likes
  • 5 in conversation