Your SAS programs, embedded in web apps and elsewhere

Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

I'm using SAS 9.4 on Windows Server 2008, I'm trying to replace an existing MS Sharepoint reporting portal (displays static excel and html files as well as executes SAS macro's for dynamic content) and was looking at the Stored Process Web Application as a possible repleacement. Can't figure out how to display a static HTML page that was created by a SAS batch process. I added the file to the Mgt. Console folder structure, but don't see it in the Web Application. Looks like it only displays Stored Proc's. Any suggestions are appreciated, I would like to use this existing reporting structure to execute my SAS macro's (as stored proc's).


Accepted Solutions
Solution
‎12-10-2013 11:05 PM
PROC Star
Posts: 1,232

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Hi,

Yes, I think we're on the same page.

So you want to display UnitGeneration.html.  Assume that file is on your Windows server, in C:\Reports\UnitGeneration.html.

You make a stored process, call it ShowUnitGeneration.  The stored process will have no prompts.

The source code of the stored process will be:

%macro BinaryFileCopy ;

%* macro code is available from the sasdummy post I cited;

%mend %BinaryFileCopy;

%macro streamfile;

%*macro code as I posted it above;

%mend streamfile;

%streamfile(file=C:\Reports\UnitGeneration.html)

The stored process source code should not use %stpbegin/%stpend, because we are writing to _webout ourselves.  The stored process must produce streaming results (not package results).

That set up should (I'm pretty sure : ) do what you want.  I did some quick testing, since I hadn't actually used %BinaryFileCopy before.

In SPWA you can navigate to the metadata folder where the stored process is.  So you will see the stored process name in the left pane (ShowUnitGeneration). And when you click the stored process name (link), the stored process will run (because there are no prompts), and results will be displayed in the right pane.  And the results will be UnitGeneration.html.

So it's not a simple <a h r e f> </ a> hyperlink in the left pane which links to UnitGeneration.html.  It's an actual stored process, but all the stored process does is stream UnitGeneration.html to _webout.

Sound reasonable/feasible?

View solution in original post


All Replies
PROC Star
Posts: 1,232

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

HI,

I'm a bit confused by your questions.

Not sure what you mean when you say you added a static html file to the SAS Mgt Console folder structure.  An html file is a file that sits on a file server.  The SMC folder structure is metadata, containing logical objects (stored processes, DI jobs, prompts) that are defined in SAS metadata.

THe stored process web app is used to run stored processes.

If you have an html file you want to display and use as a portal, you can just move the html file to your web server.  You can have links from that html page to the SPWA, where you call a stored process via the URL.  So the URL looks like href="h t t p ://MyServerSmiley Tongueort/SASStoredProcess/do?&_program=/MyStoredProcesses/MonthlyReport"

/MyStoredProcesses is a metadata folder, containing a stored process named MonthlyReport.  When someone clicks the link, the stored process will run (generating the montly report).

If you are saying you already have MonthlyReport.htm (or MonthlyReport.xlsx) sitting on your server, and you want a stored process which will display the file, yes, you could have a stored process which reads in an html file (or excel file) and streams it to _webout.  So when a user runs the stored process, they will see the web page (or get a dialog box to download/open the Excel file).

HTH,

--Q.

Occasional Contributor
Posts: 15

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Hi Quentin, yes the html and .xlsx files already exist (created outside the SAS realm) and I want to have a "link" that either displays the html/xlsx contect or as you mention a ssp that will stream to _webout. Any examples would be greatly appreciated.

Thank you.

PROC Star
Posts: 1,232

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Hi,

re streaming a file to _webout, Chris Hemedinger had a great blog post a few months ago where he shared a %BinaryFileCopy() macro written by Bruno Muller:

http://blogs.sas.com/content/sasdummy/2013/09/17/copy-file-macro/

In a stored process, you can use that macro to copy a file to _webout.  Below is an example (not very well tested).  Key point is that the stored process needs to create streaming results (not package results), and you do not want %STPBEGIN/%STPEND in the stored process code.

%macro streamfile(file=);
%local type;
filename _in "&file";

%*get extension;
%let type=%upcase(%scan(&file,-1,.));

%*if the file is not .HTML, need to tell the browser its an attachment to download;
%if &type ne HTML %then %do;
  data _null_;
    %if &type=RTF %then %do;
      rc = stpsrv_header('Content-type','application/msword');
    %end;
    %else %if &type=PDF %then %do;
      rc = stpsrv_header('Content-type','application/pdf');
    %end;
    %else %if &type=XLS or &type=XLSX %then %do;
      rc = stpsrv_header('Content-type','application/vnd.ms-excel');
    %end;
     rc = stpsrv_header('Content-disposition',"attachment; filename=%scan(&file,-1,/\)");
  run;
%end;


%binaryFileCopy(
  infile=_in
 ,outfile=_webout
  )

filename _in clear;

%mend streamfile;

%streamfile(file=/somewhere/MyExcel.xls)

Occasional Contributor
Posts: 15

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Hi Quentin, I appreciate the replies, but this is not what I'm looking to accomplish. I'm probably not explaining very well and maybe the SSPWA is not capable, but I have .html files created in the wee hours with SAS batch jobs (long running jobs), i.e. UnitGeneration.html. I'd like to be able to have a link in the folder structure of the SSPWA that displays/calls the UnitGeneration.html file and displays in the right pane of the web application. Is this doable, calling an already created html file?

Steve

Solution
‎12-10-2013 11:05 PM
PROC Star
Posts: 1,232

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Hi,

Yes, I think we're on the same page.

So you want to display UnitGeneration.html.  Assume that file is on your Windows server, in C:\Reports\UnitGeneration.html.

You make a stored process, call it ShowUnitGeneration.  The stored process will have no prompts.

The source code of the stored process will be:

%macro BinaryFileCopy ;

%* macro code is available from the sasdummy post I cited;

%mend %BinaryFileCopy;

%macro streamfile;

%*macro code as I posted it above;

%mend streamfile;

%streamfile(file=C:\Reports\UnitGeneration.html)

The stored process source code should not use %stpbegin/%stpend, because we are writing to _webout ourselves.  The stored process must produce streaming results (not package results).

That set up should (I'm pretty sure : ) do what you want.  I did some quick testing, since I hadn't actually used %BinaryFileCopy before.

In SPWA you can navigate to the metadata folder where the stored process is.  So you will see the stored process name in the left pane (ShowUnitGeneration). And when you click the stored process name (link), the stored process will run (because there are no prompts), and results will be displayed in the right pane.  And the results will be UnitGeneration.html.

So it's not a simple <a h r e f> </ a> hyperlink in the left pane which links to UnitGeneration.html.  It's an actual stored process, but all the stored process does is stream UnitGeneration.html to _webout.

Sound reasonable/feasible?

Occasional Contributor
Posts: 15

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

Nice, that worked very well.

I can now combine dynamic content in with static content on the SPWA.

Thank you.

Frequent Contributor
Posts: 148

Re: Can the SAS Stored Process Web Application display static objects, i.e. Excel files or existing HTML pages?

You should also check out the SAS autocall filesv macro/program. Here is a link to the doc for it:

FILESRV Program

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 1873 views
  • 0 likes
  • 3 in conversation