BookmarkSubscribeRSS Feed
Quartz | Level 8



I have a (huge) Stored process that can make lots of graphs depending on the parameters.

These graphs are outputted in ods html PNG format + non-embedded titles & footers, + a few other proc prints in general.


Now  I need to make a version that outputs only 1 image, (the main png that is written in an img tag in the html output)



  1. <img alt="The SGPlot Procedure" src="/SASStoredProcess/guest?_sessionid=3C3AC7BA-A50D-4BB7-8443-9DDB59150B04&_program=replay&_entry=APSWO..." style=" height: 480px; width: 640px;" border="0" class="c">
  2. /SASStoredProcess/guest?_sessionid=8E7E4609-4B45-4A95-8614-E6B4764FEC2E&_program=replay&_entry=APSWORK.TCAT0005.SGPlot.png
  3. /SASStoredProcess/guest?_sessionid=E21CFA30-10DC-4335-9540-601574329008&_program=replay&_entry=APSWORK.TCAT001A.SGPlot.png


What do you think would allow me to do that easily ?


I'm thinking adding a flag paramter to the STP

and then add a rule at the end of the STP that replaces the output 

I don't see anything else than an _webout 

with just the img tag maybe ?

, or just the png and changing the Content-type header ?



The idea would then to use it in an iframe

 or retrieve the src url and inject in a proper img tag with ajax maybe (but then I would probably face Cross-Origin Read Blocking (CORB) errors) 


Can I retrieve the _sessionid and the _entry that change every time the STP is called?



Quartz | Level 8

I think the _entry from the url

can be retrieved from _tmpcat in the stp


And the _sessionid can be found in _REPLAY

Lapis Lazuli | Level 10

I'll have a think about this. In the meantime -


Be mindful that using session IDs in your STP code like that, even temporarily, will completely circumvent load balancing at the spawner, meaning that all of your users will be redirected to the same multibridge session & that part of your application will have a concurrent capacity of 1 user. See @Vince_SAS's reply here for details. This also risks destabilising the spawner and the JVM if you're using a guest account and are intending to have this as public-facing or high-throughput app with users queuing for the session.


I'm sure there's a better way...

Quartz | Level 8

I got a simple version working. like this:


%let plotPath = &_tmpcat ; 
ods html 

* proc sgplot ;

data _null_;
	file _webout;
	put '<img style="width:100%" src="' &_REPLAY 'SGPlot2.png" >';

I could not make the STP output a binary png file yet, so I had to output html img tag.


But you are right I'm afraid 😕

If I make several iframes pointing to this STP, they load one at a time (sometimes worse, a few will encounter errors).

So it's definitely not usable on a public-facing website.


(I don't know anything about load balancing, I think we always have 1 process at a time on our sas jboss server.)




Rhodochrosite | Level 12

Is the goal to return an image file to the client, without any HTML?  If so then create a streaming stored process and use this exact code (no STPBEGIN/END) with SAS/GRAPH procedures:


goptions devide=png gsfname=_webout;

proc gchart data=sashelp.class; vbar age / discrete; run; quit;


Use this exact code (no STPBEGIN/END) with SG procedures:


ods graphics on / imagefmt=png;

filename temp temp;

ods _all_ close;

ods html file=temp gpath=_webout;

proc sgplot data=sashelp.class; hbar age; run; quit;

ods html close;


Vince DelGobbo




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
  • 4 replies
  • 1 like
  • 3 in conversation