06-16-2016 02:39 PM
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?
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');
06-17-2016 02:16 AM
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.
06-17-2016 04:19 AM
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;
06-17-2016 01:52 PM
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.
06-20-2016 02:24 AM
_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.
06-20-2016 04:23 AM
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.