Data visualization with SAS programming

split png image with sas

Reply
Contributor
Posts: 25

split png image with sas

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,

Scan

Esteemed Advisor
Posts: 5,967

Re: split png image with sas

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 6,704

Re: split png image with sas

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:

https://en.wikipedia.org/wiki/Portable_Network_Graphics

 

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 @KurtBremser 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.

Contributor
Posts: 25

Re: split png image with sas

[ Edited ]

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?

 

 

Esteemed Advisor
Posts: 5,967

Re: split png image with sas

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Community Manager
Posts: 2,601

Re: split png image with sas

As @KurtBremser 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.

SAS Super FREQ
Posts: 3,230

Re: split png image with sas

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. 

Contributor
Posts: 25

Re: split png image with sas

[ Edited ]

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
 ;
end;
run;

but it does not work.

 

I'm running on 9.4.

 

Many thanks,

Scan

SAS Super FREQ
Posts: 3,230

Re: split png image with sas

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.
Contributor
Posts: 25

Re: split png image with sas

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.

Grand Advisor
Posts: 9,719

Re: split png image with sas

Instructions at https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... turn a dataset into data step code.

 

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

Valued Guide
Posts: 505

Re: split png image with sas

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

Trusted Advisor
Posts: 1,328

Re: split png image with sas

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.

 

 

Post a Question
Discussion Stats
  • 12 replies
  • 214 views
  • 4 likes
  • 8 in conversation