BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AMUMOR_SAS
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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

20 REPLIES 20
Cynthia_sas
SAS Super FREQ
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
AMUMOR_SAS
Obsidian | Level 7

Hi,

Yes, of course there is more. 🙂 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

 

Cynthia_sas
SAS Super FREQ

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;
AMUMOR_SAS
Obsidian | Level 7
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

AMUMOR_SAS
Obsidian | Level 7

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

AMUMOR_SAS
Obsidian | Level 7

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

BrunoMueller
SAS Super FREQ

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

AMUMOR_SAS
Obsidian | Level 7

Hi,

 

Thanks for all help.

 

Regards

 

Morten Fredrik

rmedlin
Fluorite | Level 6

I'm trying to do something similar in Viya, but the stpsrv_header function doesn't exist there.  This code will produce an xlsx file in my directory, but there is no mechanism for download, as far as I can tell:

 

%let _ODSDEST = Excel;
%let _ODSSTYLE = HTMLBlue;

data _null_;

%let Report_Date = %sysfunc(date(),yymmddn8.)_%sysfunc(compress(%sysfunc(time(),time8.),%str(:)));
%let Outfile = &Report_Date._REPORT.xlsx;

%let _CONTTYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
%let _CONTENTDISP = "attachment; filename=&Outfile";

run;

ods excel file = "/home/&sysuserid/&Outfile"
options(sheet_name='Class' tab_color='purple' frozen_headers='yes');

proc print data = sashelp.class;

run;

ods excel options(sheet_name='Cars');

proc print data = sashelp.cars;

run;
niko_gallo
Obsidian | Level 7

...waiting message...

 

 

how to post a waiting message in STP?

 

 

Displaying the "Please Wait" message for a long-running stored process

AMUMOR_SAS
Obsidian | Level 7
Hi niko_gallo,

Thanks very much for this "Please Wait" Example. I'll test it.

Regards

Morten Fredrik
niko_gallo
Obsidian | Level 7

hi Morten,

 

my SAS code is similar...is:


ods excel file=_webout style=plateau;

data _null_;
rc = stpsrv_header('Content-type','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
rc = stpsrv_header("Content-disposition","attachment; filename=&_name_report._&_dt_report_ymd..XLS");
run;

proc print data =&_flnm. noobs label ;run;
ods excel close;

 

 

Cynthia_sas
SAS Super FREQ
Hi:
Your Content Type DATA _NULL_ step must be BEFORE the ODS EXCEL statement. Look again at Bruno's code in the solution to the post.
Cynthia
niko_gallo
Obsidian | Level 7

hi chintia,

 

 

the following solution it's wrong! because print the xls on the webpage...

 

data _null_;
     file _webout;
     put '<html>';
     put '<body>';
     put '<div id="pleasewait">';
     put '<h2>Please Wait. Your request is being processed.</h2>';  
     put '</div>';  
     do i = 1 to 10;
       put "                                       ";
     end;
   run;

 

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;

 

 

 

 

 

 

this is the result:

 

waiting message.png

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
  • 20 replies
  • 7818 views
  • 5 likes
  • 5 in conversation