BookmarkSubscribeRSS Feed
LukeW21
Calcite | Level 5

As a disclaimer, I am new to SAS Web Applications, Stored Processes, the ODS function, and APIs as a whole, with only introductory knowledge on the subjects as I've only just finished putting together my first web application stored process. I am aware SAS Viya has functionality for building APIs, but I do not have access to SAS Viya at my company, and it is not going to be an option before this project is needed. With that said, I am looking to get the output of a web application stored process I recently created and have it easily downloaded to whatever folder the end user designates.

 

Presently, I query some SAS Metadata and use the ODS function to load it into a temporary excel file:

 

%macro excel_output;

 filename exceltmp temp; 
 %let excelpath=%sysfunc(pathname(exceltmp)); 
 %put &=excelpath;

 ODS EXCEL file="&excelpath..xlsx" style=statistical 
 options(sheet_name="iam_sas_metadata"); 
 PROC PRINT data=sas_users noobs; 
 RUN; QUIT; 
 
 ODS EXCEL CLOSE; 

%mend excel_output;

 

 

This now creates / displays the excel spreadsheet (I enabled both the "Stream" and "Package" options when creating the stored process). But the issue is in downloading this file by means of calling the application / process like you would an API. I've tried PROC HTTP in order to replicate the API GET call to retrieve the data, although when I provided login credentials using the webusername and webpassword optional arguments, it would still only return the Logon Manager page as an html file, evidently not using the credentials I attempted to pass through to get by this page.

 

I also tried curl commands, though those either ended up failing or hanging without any log I was able to retrieve, and I tried using both verbose and piping the output of the command to a log. 

 

PROC STP does not seem like an option either as the end user is looking to be able to call the web page like a RESTful API from their end using a non-SAS program and have the excel file downloaded to their system. Does anybody know how I can set things up to make that doable, or how I might be calling the program incorrectly in order to get this to happen? Thank you in advance and please let me know if I can provide any other important details.

2 REPLIES 2
ChrisHemedinger
Community Manager

This paper might help:

https://support.sas.com/resources/papers/proceedings20/4243-2020.pdf

 

Main things to note:

- Use the special fileref _WEBOUT to direct your output to what the browser can download for the user.

- Use the stpsrv_header function to define the content type and name for the expected download. Ex:

data _null_;
  rc = stpsrv_header('Content-type','application/vnd.ms-excel');
  rc = stpsrv_header('Content-disposition','attachment; filename=output.xlsx');
run;

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
AhmedAl_Attar
Ammonite | Level 13

@LukeW21 

Here is an additional resource to look into SAS® 9.4 Stored Processes: Developer’s Guide, Third Edition 

Try to access the SAS Stored Process Web Application http://yourserver.com:8080/SASStoredProcess/do , within this web app, there are a list of Stored Process Samples, one of these samples, illustrates how to use multiple output formats "Sample: Multiple Output Formats - Using ODS to generate PDF, PostScript, RTF and other output
You can use this sample as a guide.

 

Hope this helps

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 142 views
  • 1 like
  • 3 in conversation