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)
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?
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...
I got a simple version working. like this:
%let plotPath = &_tmpcat ; ods html path=&plotPath style=xxx image_dpi=400 device=png; * proc sgplot ; data _null_; file _webout; put '<img style="width:100%" src="https://xxx.xxx.be' &_REPLAY 'SGPlot2.png" >'; run;
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.)
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;
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.
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.