Hi,
This could be a crazy idea, but I'm was wondering if I could hijack _webout to send results to a file instead of the browser, when using %stpbegin/%stpend. So far, seems like the answer is no.
Asked another way, suppose I want to write results to a file on the server (pdf/html/rtf), rather than stream them to a browser, when a user runs a stored process (through SPWA). I see 3 possibilities:
1. Wanting to use %stpbegin/%stpend in the stored process, was thinking I would try just redirecting the _webout fileref to point to a file. But clearly _webout is more than your typical fileref. So filename _webout "~/somewhere/myfile.htm" fails. Is there a way to hijack _webout?
2. Assuming I can't redirect _webout, another option would be to redefine %stpbegin(), adding a parameter for body= which would default to _webout, but allow the developer to specify an altenative. So %stpbegin(body="~/somewhere/myfile.htm") or something like that. But then there is part of me that hates the idea of putting a revised definition of %stpbegin() in my personal/project autocall library to replace the SI provided macro. Because anyone who sees %stpbegin() will assume it's calling the usual %stpbegin, and of course SAS will likely keep expanding the functionality of %stpbegin() over time.
3. Which makes me think I'll just write my own, limited, alternative to %stbegin(). A simple macro that would generate an ODS &_odsdest statement, sending results to a user-specified file, with user-specified options. Benefit of this approach is that I have control (and understanding) of what it does. But down side is I would potentially miss out on some of the magical possibilities of %stpbegin().
Currently I've been playing with #3, but was wondering if #1 is possible, or if people would share my concerns about #2.
Thanks,
--Q.
Try:
%let _ODSOPTIONS=%str(path='~/somewhere' body='myfile.htm');
options mprint;
%STPBEGIN;
proc print data=sashelp.class; run; quit;
%STPEND;
Try:
%let _ODSOPTIONS=%str(path='~/somewhere' body='myfile.htm');
options mprint;
%STPBEGIN;
proc print data=sashelp.class; run; quit;
%STPEND;
Thanks much Vince, that does the trick, and is a better approach than any of the 3 options I proposed.
Guess I need to spend more time reading through the definition of %stpbegin to see how it is parameterized. Effectively, there already is a body= parameter that defaults to _webout. But since %stpbegin doesnt have any parameters defined :smileyalert:, it's taken from &_ODSOPTIONS. After reading your solution, it of course becomes clear as day. (Below snippets from %stpbegin() with my comments added):
%*Figure out if user has specified an output file in &_ODSOPTIONS;
%let TEMPSTR=%qupcase(%qcmpres(%bquote(&_ODSOPTIONS)));
%if (%index(&TEMPSTR, BODY=) GT 0) or
(%index(&TEMPSTR, BODY 😃 GT 0) or
(%index(&TEMPSTR, FILE=) GT 0) or
(%index(&TEMPSTR, FILE 😃 GT 0) %then
%let BODYFLAG=1;
....
%*If user is streaming output and has not specified an output file, send stream to _webout;
%else %if (%qupcase(%qcmpres(&_RESULT)) eq STREAM) and
(&BODYFLAG eq 0) %then %do;
%let ODSOPT=&ODSOPT body=_WEBOUT;
%end;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.