BookmarkSubscribeRSS Feed
jack_CR
Fluorite | Level 6

Hello community!

 

I have a Stored Procedure to retrieve a report, the report is run in SAS Delivery Portal. Within my code I export that report to Excel, .csv, .HTML, .txt and PDF.
But, with the exportation on this way, the files are saved in the server and not in the local PC of the users.
¿How can I do to save the export in the local PC?

or
SAS can show a file chooser to do this?

 

My code to export:

options dev = actximg;
options orientation=landscape;
options PAPERSIZE=("32in","8in");
ods pdf file='D:\Exports\Rep_MEF4.pdf';
ods html file='D:\Exports\Rep_MEF4.html';
ods csvall file='D:\Exports\Rep_MEF4.csv';
ods listing file='D:\Exports\Rep_MEF4.txt'; 

ods tagsets.excelxp file="D:\Exports\Rep_MEF4.xls" style = Analysis 
 options (Embedded_titles = 'yes'
 Embedded_Footnotes = 'yes'
 sheet_name= 'Rep Modelo Entidades Financieras'
 autofilter= 'yes'
 frozen_headers= '5'
 autofit_height= 'No'
 absolute_column_width= '10,20,7,7'); 

 

5 REPLIES 5
Kurt_Bremser
Super User

Have a storage resource defined on the network that is accessible both by the SAS server and user's desktops, and store your results there.

Or store the results in a place where the webserver running on the SAS server can see it (like the $HOME/public_html directories on UNIXen), so users can download them with the browser.

Everything else needs some transfer tool that must be handled separately. Like WinSCP.

VasilijNevlev
Quartz | Level 8

Hey Jack, 

 

You can make the reports downloadable when the stored procedure finished running by sending it to user's session with correct HTML headers.

 

There are two steps to the process, define ODS destination and modify HTML headers. You don't need to modify HTML headers for PDF output. 

 

Here is an example, if you copy paste that into any stored process, it will just work. Let me know if you have any more questions. 

 

%global _ODSDEST _ODSSTYLE _ODSOPTIONS;

%let _ODSDEST = PDF;

%macro demo; 
  %STPBEGIN; 
     proc print data=sashelp.class; run; 
  %STPEND; 
 
%mend demo; 
 
%demo; 

 

=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk
jack_CR
Fluorite | Level 6

Thank you for reply Vasilij.

 

what do you mean with "ods destination"? it's define the ODS output type?
And when you say "Modify HTML headers" I am not sure to understand.

sorry, but I'm a beginner in SAS.

 

when I copy paste your code in a new Enterp. Guide program, I have two error:

ERROR: Unable to resolve fileref _WEBOUT. ODS PDF initialization fails.
ERROR: Logical name is not available.

 

Kurt_Bremser
Super User

_webout is a file reference (see filename statement) that is automatically created as an output stream when code runs as a stored process. If you run it as normal code in a program window, _webout is not present.

To test such code, you need to create a stored process (which you can do in Enterprise Guide) and run that.

Although, stored processes are a little bit advanced for a SAS beginner. You should master basic SAS techniques first, so you have an easier time reading and interpreting logs and debugging.

VasilijNevlev
Quartz | Level 8

Hey Jack, 

 

In your original post, you have mentioned that the report is generated by stored procedure. The code that I created for you is designed to run in a stored procedure. _webout file reference is a reserved file reference used by stored procedures to direct the output to the user's browser. You will need to open the stored procedure in your stored procedure web app to see how it works. If you don't know where the app is, ask your support team.

 

About HTTP headers (sorry, I refered to them as HTML headers in my original message), here is the link: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields The headers that I refered to, they change the description of content.  For example, if you specify this header: (Content-type:application/msword), that will tell the browser that what is being sent, is actually a word document. You can amend HTTP headers by calling stpsrv_header function like this: (stpsrv_header(Content-type,application/msword)). HTTP headers for ms excel: stpsrv_header(Content-type,application/vnd.ms-excel).

 

Let me know if you have any issues with this. 

Vasilij

=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1869 views
  • 3 likes
  • 3 in conversation