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

I am trying to create excel spreadsheet via the stored process by using Proc Export. Log suggests that file has been created without any error but when I try to open the file I get this error:

 

Excel cannot open the file 'myfile.xlsx' because the file format or the file extension is not valid. Verify that the file has not been corrupted or that the file extension matches the format of the file.

 

I am using following code in my stored process to create spreadsheets.

 

%if &Output=EXCEL %then %do;
data _null_;
   rc=stpsrv_header('Content-type','application/vnd.ms-excel');
   rc=stpsrv_header('Content-disposition',"attachment; filename=&geosumlvl._&tabname..xlsx");         
run;

proc export data=Extract_ACS outfile=_webout dbms=xlsx replace;
sheet='mysheet';
run;

%end;

I am wondering if we have a solution to resolve this issue?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Vince_SAS
Rhodochrosite | Level 12

I don't think that PROC EXPORT correctly writes to the _WEBOUT FIILEREF, even though no errors are reported.

 

Try this code and if it works, then you can adapt it to your data:

 

ods _all_ close;

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

%let WORKPATH=%sysfunc(pathname(work));

filename temp "&WORKPATH/temp.xlsx";

proc export data=sashelp.class 
  outfile=temp 
  dbms=xlsx 
  replace;
  sheet='mysheet';
run; quit;

data _null_;
infile temp recfm=f lrecl=1;
file _webout recfm=n;
input;
put _infile_;
run;

 

Vince DelGobbo

SAS R&D

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

What SAS version are you using? XLSX only became available in 9.4M2. Try XLS also.

ballardw
Super User

Is your Excel 32-bit or 64-bit? The 32-bit versions don't like opening 64-bit files.

Vince_SAS
Rhodochrosite | Level 12

I don't think that PROC EXPORT correctly writes to the _WEBOUT FIILEREF, even though no errors are reported.

 

Try this code and if it works, then you can adapt it to your data:

 

ods _all_ close;

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

%let WORKPATH=%sysfunc(pathname(work));

filename temp "&WORKPATH/temp.xlsx";

proc export data=sashelp.class 
  outfile=temp 
  dbms=xlsx 
  replace;
  sheet='mysheet';
run; quit;

data _null_;
infile temp recfm=f lrecl=1;
file _webout recfm=n;
input;
put _infile_;
run;

 

Vince DelGobbo

SAS R&D

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
  • 3 replies
  • 5501 views
  • 0 likes
  • 4 in conversation