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

Hi,  I hope someone can help!

I've managed to output a formatted tabulate table to a PNG file to use as part of a dashboard that I'm playing with - however, when I use gslide/greplay to bring the file back in to a PDF file it returns the image with lots of excess white space - is there a way that i can automatically reduce the dimensions of the PNG file to the displayable size of the table?

thanks in advance!

Antony

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Here's the thing. When I first saw your code, I thought -- hmmm -- I wonder how that's even working -- using PRINTERPATH=PNG. But I set those thoughts aside for a while because there was another, more obvious problem. And the obvious problem is that I just saw a TABULATE and a GSLIDE -- neither of those would pay any attention to the ODS GRAPHICS statement -- that statement ONLY has an impact on the SG procedures, SGPLOT, SGPANEL, SGRENDER or the procedures that automatically produce images because of ODS GRAPHICS (like PROC FREQ, UNIVARIATE, REG, ANOVA, etc, etc) but I can tell you for sure, that TABULATE and GSLIDE don't take instructions or settings from the ODS GRAPHICS statement.

  And, while GSLIDE would be impacted by the GOPTION statement, I'm not sure you needed it. Once you have your image in a PNG file, you could just directly insert the PNG file into your dashboard. If you used ANNOTATE, I think you can insert an image at a particular location. If you were going to put more than one image on your GSLIDE, then I'm not sure the IBACK idea will work.

  Anyway, when I tried your code, without the ODS GRAPHICS statement and without the GSLIDE, I was surprised to find that a PNG file had been created. So I'm not sure that you actually need your GSLIDE and IBACK. I was able to use PAPERSIZE= system option to change the amount of white space that was created in the original image (with the help of a very savvy graph person in Tech Support). My original idea was to fiddle with margins, but his idea was to alter papersize and his approach is better.

  I attached a few screenshots that show the image opened in my default picture viewer and another that shows the image properties.

cynthia

  

   options printerpath=png nodate papersize=('5.75in','4.75in');

ods _all_ close;

ods printer file="c:\temp\table_image.png";

proc tabulate data=sashelp.class;

  where age ge 14;

  title 'Table Title as Part of Image';

  class age sex;

  var height;

  table age,

        sex='Gender'*height=' '*(n min mean max);

run;

ods printer close;

ods listing;


get_rid_white_space.pngpng_file_properties.png

View solution in original post

14 REPLIES 14
GraphGuy
Meteorite | Level 14

We'll need a lot more info to diagnose this problem ...

How did you ouptut the formatted table to a png file?

When you look at this png file before you use gslide/greplay to put it in the dashboard,

does it already have the extra white-space in it at that time?

to_the_point
Calcite | Level 5

Hello,

thanks for the quick replay - i like your webpage by the way, but it's way more advanced than i can cope with! 😉

I output to a png like this:

ods graphics on / width=6in imagefmt=png imagemap=on imagename="table" border=off;

options  printerpath=png nodate;

ods html close;

ods printer file="c:\....\table.png" style=barrettsblue;

proc tabulate data=table;

.........

ods printer close;

ods html;

goptions reset=all iback="c:\....\table.png" imagestyle=fit;

proc gslide name='table';

run;

quit;

and yes the white space is there before I bring it back so I'm assuming it's either an option on the ods printer setup or it's completely the wrong way to do!

cheers

Antony

ballardw
Super User

In which dimension is the objectionable white space appearing? Horizontal, vertical or both? You may need to adjust graphics width and height based on the number of rows and columns you are requesting in proc tabulate. That might be easier to do if you use style overrides to set column widths and row heights.

to_the_point
Calcite | Level 5

Thanks - I've tried modifying the height and width dimensions but it doesn't seem to matter.

thanks

A

Cynthia_sas
SAS Super FREQ

Hi:

  Here's the thing. When I first saw your code, I thought -- hmmm -- I wonder how that's even working -- using PRINTERPATH=PNG. But I set those thoughts aside for a while because there was another, more obvious problem. And the obvious problem is that I just saw a TABULATE and a GSLIDE -- neither of those would pay any attention to the ODS GRAPHICS statement -- that statement ONLY has an impact on the SG procedures, SGPLOT, SGPANEL, SGRENDER or the procedures that automatically produce images because of ODS GRAPHICS (like PROC FREQ, UNIVARIATE, REG, ANOVA, etc, etc) but I can tell you for sure, that TABULATE and GSLIDE don't take instructions or settings from the ODS GRAPHICS statement.

  And, while GSLIDE would be impacted by the GOPTION statement, I'm not sure you needed it. Once you have your image in a PNG file, you could just directly insert the PNG file into your dashboard. If you used ANNOTATE, I think you can insert an image at a particular location. If you were going to put more than one image on your GSLIDE, then I'm not sure the IBACK idea will work.

  Anyway, when I tried your code, without the ODS GRAPHICS statement and without the GSLIDE, I was surprised to find that a PNG file had been created. So I'm not sure that you actually need your GSLIDE and IBACK. I was able to use PAPERSIZE= system option to change the amount of white space that was created in the original image (with the help of a very savvy graph person in Tech Support). My original idea was to fiddle with margins, but his idea was to alter papersize and his approach is better.

  I attached a few screenshots that show the image opened in my default picture viewer and another that shows the image properties.

cynthia

  

   options printerpath=png nodate papersize=('5.75in','4.75in');

ods _all_ close;

ods printer file="c:\temp\table_image.png";

proc tabulate data=sashelp.class;

  where age ge 14;

  title 'Table Title as Part of Image';

  class age sex;

  var height;

  table age,

        sex='Gender'*height=' '*(n min mean max);

run;

ods printer close;

ods listing;


get_rid_white_space.pngpng_file_properties.png
to_the_point
Calcite | Level 5

Cynthia, thanks for that - that seems to solve it for me. 

I got the idea for the ods printerpath=png from an old post on the community that you responded to and it seemed to work for proc tabulate as well so step 1 for me was done.  I was using the gslide to get the image in to the gseg directory so i could use proc greplay to place the table in to a grid - I haven't yet worked out the annotate functionality which I think would be a much more elegant solution especially if i could use it to place non-png files in to the dashboard - do you have an example that you could share?  If not, don't worry, I'll plug on testing ideas.

thanks again

Antony

Cynthia_sas
SAS Super FREQ


Hi:

  I am not sure your will like the resolution of the output if you save your png of the tabulate into a gseg and then try to replay it again at a smaller size for your dashboard.

  Yes, annotate is a more elegant solution and on Rob Allison's web site there is an example of Scout camps in NC, where he annotates an image onto a location on a map:

Boy Scout Camps in North Carolina (NC)

http://robslink.com/SAS/democd25/scouts_info.htm and then the relevant piece of annotate code is where he assigns an image to play into the image at the correct x/y coordinates and provides the image name in the annotate dataset (where he's writing out the red symbol or the black one):

   x=x-sizer; y=y-sizer;

   function='move';

   output;

   sizer=sizer*.85;

   x=x-sizer;

   y=y-sizer;

   output;

   imgpath='bsa.gif'; style='fit';

   function='image'; x=x+(sizer*2); y=y+(sizer*2); output;

There are a lot of good user group papers and books about using ANNOTATE that break down how it works. Or, the new SG procedures allow you to put the equivalent of a TABLE into an image form. Depending on the version of SAS you have, you may be able to use ODS GRAPHICS to do some of what you want, too.

cynthia

to_the_point
Calcite | Level 5

Thanks again - I'm using 9.3 so the SG procedures/ODS graphics sounds interesting - do you have an example of that too?

Antony

saidi
Fluorite | Level 6

Hi Cynthia,

I used the same SAS code for the Proc Print instead of the Proc Tabulate. Here my purpose is to generate the total sashelp.air table into the .PNG format.

But following SAS code is converting first page(only first 23 observations data) of the report into the .PNG format.

If i want to get the total report into the .PNG file format (in one PNG file or different PNG files) is there any options/statement/SAS code i have to modify in the following code please suggest me.

Thanks in advance.

saidi.

options printerpath=png nodate papersize=('12.0in','7.5in');

ods _all_ close;

ods printer file="c:\temp\table_image.png";

proc print data=sashelp.air;

run;

ods printer close;

ods listing;

Cynthia_sas
SAS Super FREQ

Hi,

  In general, it isn't a good idea to piggyback on someone else's already solved posting. It would be better to start a new post and then reference the older post in your remarks.

  I would expect that the technique described in this original post would only work or work best for small, single-page tables. It looks to me that if I sent SASHELP.AIR (144 obs) directly to a printer or to a PDF file, it would take about 5 or 6 physical pages, depending on the margins and fonts used, etc, etc. My guess would be that you would need to use multiple PROC PRINT steps, using FIRSTOBS= and OBS= to control the number of observations displayed for each step, with a different FILE= option for ODS PRINTER for each step in order to generate multiple files.

  You'd have to check with Tech Support to be sure. I don't know whether PAPERSIZE= changes would do any good if you made the vertical dimension really big. My guess is that the report would either still get truncated or the image would be really small in a viewer. I think that Tech Support is your best bet for help.

  But I'm trying to think of having even 50 obs to look at in an image file -- what is the end goal of having a table that big in a format that would be 1) hard to print and 2) probably hard to read? I use PDF for multi-page reports because it is very hard to edit PDF files and they do print well and with the PDF controls in Adobe Acrobat Reader, you can easily zoom or fit to page for reading/review purposes.

cynthia

saidi
Fluorite | Level 6

Hi,

Thanks for your reply. I am new to this community; I would take you suggestion to my new posts.

Here SASHELP.AIR is an example I used to relate my situation, I sometimes have to report directly a data set or a Proc tabulate reports.

Your suggestion using the FIRSTOBS= & OBS= and PAPERSIZE= options are working well for the data set. But same thing unable apply for the PROC TABULATE because we cannot expect the report size.

Yes, reports are giving in .PDF & other formats and user wanted reports in .PNG format also. I would check with the SAS Tech Support.

Thanks,

Saidi.

Cynthia_sas
SAS Super FREQ

Hi:

  For TABULATE, you could use BY group processing or multiple runs of TABULATE with a WHERE statement in order to get smaller tables. I would not expect that TABULATE is as easy to predict as PRINT and probably will NOT lend itself well to making a PNG file of the output. I still think Tech Support can help you here. Personally, I think the PNG approach is relatively useless for anything other than really SMALL tables.

cynthia

GraphGuy
Meteorite | Level 14

I've taken your technique for creating a SAS table in a png file, and integrated it with a traditional SAS/Graph (using annotate).

I'm not sure that I've got it narrowed down to just the minimum/most-elegant code, but I thought I'd share what I have so far...

Here's the output:

http://robslink.com/SAS/democd56/table_image.htm

And here's the "info" page (with a link to the SAS code):

http://robslink.com/SAS/democd56/table_image_info.htm

to_the_point
Calcite | Level 5

Thanks - very helpful.

regards

Antony

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 10062 views
  • 5 likes
  • 5 in conversation