3

Is there a way to import the first sheet from an excel file, without specifying the name of the sheet.

PROC IMPORT  
  DATAFILE= "filePath\fileName.xlsx" 
  DBMS=EXCEL REPLACE
  OUT= _fileName_OUT.;
  SHEET = 'sheetName';
  GETNAMES=YES;
  MIXED=NO;
  SCANTEXT=YES;
  USEDATE=YES;
  SCANTIME=YES;
RUN;

So instead of using the "sheetName" parameter, I am looking for a generic term that would specify that it should be the first sheet in the excel file.

1 Answer 1

4

SAS automatically imports the "first" sheet in the excel file, for a certain definition of first, if you don't use the sheet statement. So if you simply proc import the file without specifying sheet, you'll get whatever the first is. But it won't be necessarily the left-most; it's the first in Excel's internal thinking.

Also, the dbms you use matters. EXCEL and XLSX do different things. EXCEL seems to take the original SHEET1; XLSX seems to take the left most sheet, by default.

Sign up to request clarification or add additional context in comments.

4 Comments

unfortunately, that does not work. ERROR: Expecting a valid sheet name or range name.
Did you leave sheet in there and just not give it a value? I meant to leave off the sheet statement entirely. That certainly works.
I just commented out the sheet statement and ran the script and got the error... maybe it has to do with the SAS version (I have SAS 9.3), but it's not working for me - I have to either define a RANGE or a SHEET.
No, this has worked since 9.1.3 at least; I've done it since then. Sheet has never been mandatory... something else is going on, or you have something complex in your environment that you're not explaining.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.