Your SAS programs, embedded in web apps and elsewhere

Can I hijack _webout?

Accepted Solution Solved
Reply
PROC Star
Posts: 1,322
Accepted Solution

Can I hijack _webout?

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.


Accepted Solutions
Solution
‎08-07-2012 08:25 AM
SAS Super FREQ
Posts: 304

Re: Can I hijack _webout?

Try:

%let _ODSOPTIONS=%str(path='~/somewhere' body='myfile.htm');

options mprint;

%STPBEGIN;

  proc print data=sashelp.class; run; quit;

%STPEND;

View solution in original post


All Replies
Solution
‎08-07-2012 08:25 AM
SAS Super FREQ
Posts: 304

Re: Can I hijack _webout?

Try:

%let _ODSOPTIONS=%str(path='~/somewhere' body='myfile.htm');

options mprint;

%STPBEGIN;

  proc print data=sashelp.class; run; quit;

%STPEND;

PROC Star
Posts: 1,322

Re: Can I hijack _webout?

Posted in reply to Vince_SAS

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 616 views
  • 1 like
  • 2 in conversation