DATA Step, Macro, Functions and more

import excels whose format and extension don't match

Reply
Occasional Contributor
Posts: 7

import excels whose format and extension don't match

Hi SAS experts:

 

Is there anyway we can import excels into SAS when excels' format does not match the extension? See attached photo. I can open the excel by simply clicking "yes." 

 

Here is the SAS log:

 

2181 PROC IMPORT OUT=jpmorgan DATAFILE= "C:\Users\Research.xls" DBMS=xls REPLACE;
2181! GETNAMES=YES; RUN;

Spreadsheet isn't from Excel V5 or later. Please open it in Excel and Save as V5 or later
Requested Input File Is Invalid
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

Thank you!

 

format not match extension.PNG

Super User
Posts: 13,297

Re: import excels whose format and extension don't match

Posted in reply to Shortselling123

Easiest might be to open the "xls" file in Excel and do a File Save As into a CSV file and import that.

 

Or do a File Save As to XLSX using Excel as recommended by the SAS error message.

Occasional Contributor
Posts: 7

Re: import excels whose format and extension don't match

Thanks. Unfortunately I have thousands of such excels and it is very time consuming to change format manually.
Super User
Posts: 23,247

Re: import excels whose format and extension don't match

Posted in reply to Shortselling123

Then you're best off using a VBS script to convert them all to XLSX. There's a SAS macro on here that does it, see the link below:

 

http://support.sas.com/kb/43/496.html

 

Once they're XLSX you can use PROC IMPORT. If the file formats are the same though, you may want to consider CSV instead. You can change the type by changing the number  and extension on the Excel file Save As command:

 

 mybook.SaveAs ""&default.\"" & Filename & "".xlsx"", 51";

 

CSV looks to be Number 6 instead:

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/xlfileformat-enumeration-excel

 

Hi SAS experts:

 

Is there anyway we can import excels into SAS when excels' format does not match the extension? See attached photo. I can open the excel by simply clicking "yes." 

 

Here is the SAS log:

 

2181 PROC IMPORT OUT=jpmorgan DATAFILE= "C:\Users\Research.xls" DBMS=xls REPLACE;
2181! GETNAMES=YES; RUN;

Spreadsheet isn't from Excel V5 or later. Please open it in Excel and Save as V5 or later
Requested Input File Is Invalid
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

 

Thank you!




Occasional Contributor
Posts: 7

Re: import excels whose format and extension don't match

That is great. Thank you! Later one friend solved this problem for me by writing some python codes. 

Ask a Question
Discussion stats
  • 4 replies
  • 258 views
  • 0 likes
  • 3 in conversation