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

Perhaps an odd question, but...

How can I have a stored process open a static html/pdf/rtf/SASREPORT file that is sitting on the server?  By "open" I mean display the results if it is html or SASREPORT, prompt the user to open or download if it is pdf/rtf.  Process will be called from SPWA and/or WRA, on the stored process server.

Background is that I am imaging a stored process where I will:

1. Run a report and write the report to a file (html/pdf/rtf/SASREPORT), but NOT display the results to the user.

2. Scan the log from running the report.

3. If the log is clean, I will want to display the report.  If the log has errors, I will display an error message.

My first thought was to use ODS document to generate the report (without displaying in).  Then I can conditionally REPLAY the document inside of %STPBEGIN / %STPEND to display the results.

That works okay, but I lose some minor formatting which isn't captured in the document (e.g. page break info).

So I was thinking I could just use good old ods html/pdf/rtf to write a file to a temp location on the server, and then conditionally display it.

But once the file is wrtten, I'm not sure how to display it?  I think I basically want to push the file back to _webout (with the appropriate header indicating it's an attachement when it is rtf or pdf or SASREPORT).  Maybe for html it's as simple as  something like:

  data _null_;

    file _webout;

    infile "file";

    input;

    put _infile_;

  run;

?

But not sure how it would work for pdf/rtf, and Henderson's book is at the office....


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
Quentin
Super User

I think I've got streaming of a file back to _webout working.  Instead of using %filesrv for the pdf, I found a tip on serving a binary file: http://support.sas.com/kb/6/588.html  .

Below is my current code for streaming a file sitting on the server (html, rtf , pdf):

data _null_;
  file _webout;
  infile myhtml;
  input ;
  put _infile_;
run;

data _null_;
  file _webout;

  infile myrtf;

  if _n_ = 1 then do;
    rc = stpsrv_header('Content-type','application/msword');

    rc = stpsrv_header('Content-disposition',"attachment; filename=SampReplay_rtf.doc");

  end;
  input ;
  put _infile_;
run;

data _null_;
  file _webout recfm=s;
  infile  mypdf recfm=n;
  if _n_ = 1 then do;
    rc = stpsrv_header('Content-type','application/pdf');
    rc = stpsrv_header('Content-disposition',"attachment; filename=SampReplay_pdf.pdf");
  end;
  input c $char1.;
  put c $char1. @@;
run;

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.

View solution in original post

7 REPLIES 7
Jay_TxOAG
Quartz | Level 8

Why would you have errors? (beyond the initial testing)...I do this with RTF, but I just stream the results back and the browser opens MS Word for the user and displays the results.

Just curious why you would have unexpected errors...

Quentin
Super User

Hi, Jay, Thanks for replying.

I actually haven't tried this yet, so can't tell you what errors I have hit (may be posting more this afternoon...).  I assumed this method might not work with a PDF file, since it is not a text file. I would expect RTF and SASREPORT (xml) to be easier.

Looking around a bit, looks like maybe I need to use %filesrv?

  http://support.sas.com/rnd/web/intrnet/filesrv/filesrv.html

Have you seen any (simple-ish) examples of writing having one requeset that writes a rtf/pdf to somewhere on the server, and then streams that file back to the user?  

Thnaks,

--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.
Jay_TxOAG
Quartz | Level 8

Quentin,

Why do you need to store the file on the server? Why not just stream it to the user....

Quentin
Super User

Jay,

As described in my first post, I'm trying to set up a process where when a user submits a stored process to generate a report, the stored process will scan the SAS log for any problematic messages (errors, warnings, or bad notes), and if there are bad messages, will return those to the user, instead of the report.  So it's roughly:

1. Run a report and write the report to a file (html/pdf/rtf/SASREPORT), but do NOT display the results to the user.

2. Scan the log from running the report.

3. If the log is clean, I will want to stream the report to user.  If the log has errors, I will display an error message to the user.

[Another option I played with was using ods document as a tool to hold the report and later replay it.]

I'm new to working on stored processes/application development for use by non-programmers.  As a SAS programmer, I always run a %logcheck on my log before trusting (even looking at) results. So I feel like as a developer, I should give users the same level of error-detection.  Of course ideally code will trap errors before they are encountered.  But especially in the BI world, where the person who programs a stored procedure may not have any control over the live source databases that are inputs to the procedure, it seems worth checking the log, rather than assuming that if SAS returned a result, everything must have run fine.

But I'd be happy to hear thoughts from you or others on this sort of approach.  I've tried to start threads here and on SAS-L, with little interest generated.  So maybe I'm off-base.  But in my gut, I feel like it would be close to negligence to release an application that used SAS but completely ignored the SAS log....

--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.
Jay_TxOAG
Quartz | Level 8

I didn't mean to imply that your concern is not justified. I have only worked in one SAS shop, so I am curious how other places work.

However, if you don't have control over the data that is being used for your BI reports...then I think that is a big problem.

Quentin
Super User

I share your curiousity (I've worked in several SAS shops, but this is my first time working in BI).

I guess I meant I personally do not have control overt the databases that my stored processes consume.  The databases themselves are maintained by the DBAs.

So I could "trust" the databases (that all the integrity constraints are defined, etc etc).  And then if bad data snuck in and somebody noticed  my stored process returned an incorrect report, I would claim "Garbage in, Garbage out, blame the DBA."

But over the years, I've learned NOT to trust that data are clean (even when I do manage the database : )   And if a report generated by my stored procedure is incorrect, I don't thin folks will be happy with finger-pointing. So if the SAS log can tell me that missing values were created for some records because values were missing/invalid  (or a 100 other messages), I don't want to return a misleading report to the user.

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.
Quentin
Super User

I think I've got streaming of a file back to _webout working.  Instead of using %filesrv for the pdf, I found a tip on serving a binary file: http://support.sas.com/kb/6/588.html  .

Below is my current code for streaming a file sitting on the server (html, rtf , pdf):

data _null_;
  file _webout;
  infile myhtml;
  input ;
  put _infile_;
run;

data _null_;
  file _webout;

  infile myrtf;

  if _n_ = 1 then do;
    rc = stpsrv_header('Content-type','application/msword');

    rc = stpsrv_header('Content-disposition',"attachment; filename=SampReplay_rtf.doc");

  end;
  input ;
  put _infile_;
run;

data _null_;
  file _webout recfm=s;
  infile  mypdf recfm=n;
  if _n_ = 1 then do;
    rc = stpsrv_header('Content-type','application/pdf');
    rc = stpsrv_header('Content-disposition',"attachment; filename=SampReplay_pdf.pdf");
  end;
  input c $char1.;
  put c $char1. @@;
run;

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
  • 7 replies
  • 2863 views
  • 0 likes
  • 2 in conversation