BookmarkSubscribeRSS Feed
Obsidian | Level 7

Dear All,

is it possible to split a single png image into two different png files with SAS?


Let's say dividing a file IMAGE.png into the upper 80% portion of the image and the 20% on the bottom, saving them as TOP.png and BOTTOM.png, keeping the same resolution?


Many thanks, any hint appreciated,


Super User

SAS is really not an image manipulation utility. I'd suggest dedicated software like IrfanView, Potoshop or gimp for this.

gimp should have something that can be used from the commandline.

Diamond | Level 26 RW9
Diamond | Level 26

Well, yes, it is possible.  Depends if you have 6 months or so to write a parser for the filetype.  File format is given here:


Nothing stopping you form reading in the binary data, manipulating as you want, then writing out. 


Is this a good idea, no.  Why are you attempting to use a picture?  Go back to the srouce data, and regenerate the output with the part you want.  Alternatively use a paint app as @Kurt_Bremser has said, however I personally see that as not being a good idea either, the whole picture would be there for a reason, chopping out a certain bit of it just removes most of the consolidating reference data.  Take for example a graph, the axis is there so the points have reference, you could chop out a bit, but does it still convey anything.

Obsidian | Level 7

Thank you all,


I need to do it in SAS and no, unfortunately I don't have 6 months.


Any workaround? As an example I think that probably it is possible trying to fit it in a smaller box, basically cutting the bottom side of the image. But what about the upper side?



Super User

Let's repeat: SAS does NOT have built-in image manipulation tools. Period. To manipulate an existing image, you would have to write that byte-by-byte yourself. Use a proper tool (easily available for all platforms, as mentioned) to do this.

Community Manager

As @Kurt_Bremser and @RW9 have said, it's probably better to examine what you need for these images and try to build the graphs natively in SAS based on your data, rather than post-process the image.

SGPLOT supports a "broken axis" that might help you to segment your report.  Otherwise, you might be able to build what you need in GTL.  You can start with the ODS Graphics Designer to build a layout with your data, which will generate the code that you can then process with PROC SGRENDER.


Please post your image so we can see what is in it. Also post the version of SAS that you are using.

We can then suggest ways to produce output that might meet your business objectives. 

Obsidian | Level 7

Thanks for the interest.


Basically I have a KM graph with patients at risk at the bottom.

This is produced with a layout lattice with united datarange in order to align the two elements.

I want to produce 2 different png mantaining the alignment.


I solved for the moment creating 2 different png files with the same templating simply changing the vertical dimension of the graph and assigning the row dimension to (0.99 0.01) to the km graph and (0.01 0.99) to the second element with pt at risk.

I still have the labels of the second element creating a black box on the left bottom of the km graph, solved it whitening the text.


This is very dirty but works.

If you have better hints on how to proceed I will be glad to accept them.


Is there a way to delete the space between the border of the graph (max y-axis) and the border of the image (on the top)?

Because I'm actually having a lot of space between the first and second element. 

I tried to define a style with 


proc template;
define style NEWSTYLE;
parent = styles.listing ; 
replace Body from Document /
 bottommargin = 0 cm
 topmargin = 0 cm
 rightmargin = 0 cm
 leftmargin = 0 cm
 replace Body from Output /
 bottommargin = 0 cm
 topmargin = 0 cm
 rightmargin = 0 cm
 leftmargin = 0 cm

but it does not work.


I'm running on 9.4.


Many thanks,



Let's repeat one more time. If you would like help, please post

  1. Your image so we can see what is in it.
  2. The version of SAS that you are using.
  3. The SAS syntax and sample data would be especially welcome, especially if the data is from a SASHelp data set or from the documentation.
Obsidian | Level 7

Thank you Rick,

probably tomorrow I'll be free to adapt the code to a sashelp dataset.

As you know I can't post code/datasets before making it completely generalised.

Many thanks for the help so far, not only today.

I'll return here with the requested things.

Super User

Instructions at turn a dataset into data step code.


It shouldn't be hard to obfuscate a few variables to demonstrate what you are doing.

Barite | Level 11

Do you have the IML interface to R?  Can you call Python?

Tourmaline | Level 20

If you create your plots with SAS/GRAPH (proc gplot rather than proc sgplot), you can use proc greplay to put them back together as one plot, positioning them as you like, including overlapping to hide parts of some graphs.


As far as I know, the SG procedures cannot output to catalog, and there is no proc sgreplay.





Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 12 replies
  • 8 in conversation