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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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
Super User

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;

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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