BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
1 ACCEPTED SOLUTION

Accepted Solutions
Vince_SAS
Rhodochrosite | Level 12

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

2 REPLIES 2
Vince_SAS
Rhodochrosite | Level 12

Try:

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

options mprint;

%STPBEGIN;

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

%STPEND;

Quentin
PROC Star

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;

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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
  • 2 replies
  • 1386 views
  • 1 like
  • 2 in conversation