The SAS Output Delivery System and reporting techniques

Stored Process - output to XLSX

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Stored Process - output to XLSX

Hello,

We have several STP programs that uses the following output in Excel:

 

 %if &Valg. = EXCEL %then %do;

data _null_;

 

/* Set HTTP headers */

  rc = stpsrv_header('Content-type','application/vnd.ms-excel');

 

 /* Prompt to SAVE or OPEN the attachment file named test.xls using Excel */

rc = stpsrv_header('Content-disposition','attachment; filename=filename.xls');

run;

%End;

 

What do I have to do to get a prompt to SAVE ot OPEN for XLSX?

 

Regards

Morten Fredrik Amundsen


Accepted Solutions
Solution
‎04-18-2017 09:31 AM
SAS Super FREQ
Posts: 708

Re: Stored Process - output to XLSX

Posted in reply to AMUMOR_SAS

Hi

 

Have a look here https://communities.sas.com/t5/SAS-Stored-Processes/ODS-EXCEL-in-Web-StoredProcess/td-p/286083

 

Basicaly you will use the follwoing code:


data _null_;
  rc = stpsrv_header('Content-type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  rc = stpsrv_header('Content-disposition','attachment; filename=try3.xlsx');
run;

ods excel file = _webout style=Plateau;
proc print data=sashelp.cars;
run;
ods excel close;

make sure you do not have the %stpbegin and %stpend somewhere in your code.

 

Bruno

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,868

Re: Stored Process - output to XLSX

Posted in reply to AMUMOR_SAS
Hi:
There has to be more to your stored process than the content-type header. What destination are you using or what does the rest of your code look like? Are you using an ODSDEST override or using _WEBOUT? Are you using %STPBEGIN? How are you invoking this SP? In the Information Delivery Portal or using the Stored Process Web App? There is a separate forum for Stored Processes and you might find more help there. But they will want to know the same information. Just showing the content-type header is not enough information.

Cynthia
Contributor
Posts: 27

Re: Stored Process - output to XLSX

Posted in reply to Cynthia_sas

Hi,

Yes, of course there is more. Smiley Happy I'm sorry that my information was'nt acurate enough.

I am using ODSDEST override, and %STPBEGIN and %STPEND. I invoke the STP using the Delivery Portal.

 

Regards

 

Morten Fredrik Amundsen

 

SAS Super FREQ
Posts: 8,868

Re: Stored Process - output to XLSX

[ Edited ]
Posted in reply to AMUMOR_SAS

And for the ODSDEST override, your destination is??? MSOFFICE2K? TAGSETS.EXCELXP? CSV?

I don't understand the rest of your question: "What do I have to do to get a prompt to SAVE ot OPEN for XLSX?" When I run a stored process that creates Excel output using TAGSETS.EXCELXP for example after I supply the prompts, the SP runs and I get prompted by the browser to either Open or Save the file. SAS doesn't control that popup window, it comes from the browser. I have some examples of code we used in the Stored Process class -- but they used TAGSETS.EXCELXP because that version of the class was before ODS EXCEL was available.

cynthia

 

My suggestion is that you try each of these SPs separately, as simple stored processes, outside of your fancy macro code. These only do a PROC PRINT with SASHELP.CLASS, no LIBNAME needed. You should be able to simply register these and then run them to see which one works best. (I like method #1 with _webout because if I have suboptions to pass in I think it is easier to use this method then %stpbegin.)

** Test 1: TAGSETS.EXCELXP with _Webout;
data _null_;
  rc = stpsrv_header('Content-type','application/vnd.ms-excel;');
  rc = stpsrv_header('Content-disposition','attachment; filename=try1.xls');
run;
ods listing close;

ods tagsets.excelxp body=_webout style=sasweb;

  proc print data=sashelp.class noobs;
    title 'test1 excelxp mimetype=application/vnd.ms-excel';
  run; 

ods tagsets.excelxp close;

** Test 2: TAGSETS.EXCELXP with %stpbegin;

%global _odsdest _odsstyle _odsstylesheet;

%let _odsdest=tagsets.excelxp;
%let _odsstyle=sasweb;
%let _odsstylesheet=;

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

*ProcessBody;
%stpbegin;

  proc print data=sashelp.class noobs;
    title 'test2 excelxp mimetype=application/vnd.ms-excel';
  run; 

%stpend;

** Test 3: ODS EXCEL (if you have 9.4) with %stpbegin;

%global _odsdest _odsstyle _odsstylesheet;

%let _odsdest=excel;
%let _odsstyle=sasweb;
%let _odsstylesheet=;

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

*ProcessBody;
%stpbegin;

  proc print data=sashelp.class noobs;
    title 'test3 ods excel mimetype=application/vnd.ms-excel';
  run; 

%stpend;
Contributor
Posts: 27

Re: Stored Process - output to XLSX

Posted in reply to Cynthia_sas
Hello again,
When I run SP that creates Excel, I use destination MSOFFICE2K. I get prompted by the browser to either Open or Save the excel file. This creates the old excel format (xls).
I want to create the new excel format, xlsx. Which destination should I use to make it work?

Regards
Morten Fredrik Amundsen

Contributor
Posts: 27

Re: Stored Process - output to XLSX

Posted in reply to AMUMOR_SAS

Hello,

 

When I am running your example Try3, I get prompted by the browser to eiter open or save the excel file. I choose save. When I then try to open it, I get an error message that says that either the file format or filetype is Invalid. Why do I get this message?

 

Regards

 

Morten Fredrik

Contributor
Posts: 27

Re: Stored Process - output to XLSX

Posted in reply to AMUMOR_SAS

Hello again,

 

I have tryed all three examples that you did post me. Both Example1 and Example2 where successful, but Example3, in which the excel file Try3 was created, was unsuccessful.

The excel file Try3 is created, but it is impossible to open. As I mentioned earlier, I get an error message which tells me that either the file format or file type is invalid. How come?

 

Regards Morten Fredrik

Solution
‎04-18-2017 09:31 AM
SAS Super FREQ
Posts: 708

Re: Stored Process - output to XLSX

Posted in reply to AMUMOR_SAS

Hi

 

Have a look here https://communities.sas.com/t5/SAS-Stored-Processes/ODS-EXCEL-in-Web-StoredProcess/td-p/286083

 

Basicaly you will use the follwoing code:


data _null_;
  rc = stpsrv_header('Content-type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  rc = stpsrv_header('Content-disposition','attachment; filename=try3.xlsx');
run;

ods excel file = _webout style=Plateau;
proc print data=sashelp.cars;
run;
ods excel close;

make sure you do not have the %stpbegin and %stpend somewhere in your code.

 

Bruno

Contributor
Posts: 27

Re: Stored Process - output to XLSX

Posted in reply to Bruno_SAS

Hi,

 

Thanks for all help.

 

Regards

 

Morten Fredrik

☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 353 views
  • 3 likes
  • 3 in conversation