Help using Base SAS procedures

Graceful ways to handle missing data from a Proc Import of .xls files

Accepted Solution Solved
Reply
Regular Contributor
Posts: 179
Accepted Solution

Graceful ways to handle missing data from a Proc Import of .xls files


Hi,

I'm looking for ideas on how to handle error conditions from a missing or renamed tab when using Proc Import in a batch mode.  I've been asked to read in a lot of older excel files, each of which has multiple tabs.  I can easily detect if the file itself is present with the fileexist() function.  Not so much with a missing or mis-named tab within the spreadsheet.

Each proc import is followed by a data step to transform it, then a proc append.  If proc import doesn't find the tab, it won't create the output file as it doesn't know what to put in it.  The data step then chokes on a missing input dataset.

Thanks!

--Ben


Accepted Solutions
Solution
‎11-19-2014 04:09 PM
Super User
Posts: 3,252

Re: Graceful ways to handle missing data from a Proc Import of .xls files

Posted in reply to BenConner

You could try a LIBNAME statement with the EXCEL option. When you assign your LIBNAME to a workbook, all of the tabs will be listed in a PROC CONTENTS of the library. You could also use the EXIST function to test if a tab is present or not.

View solution in original post


All Replies
Solution
‎11-19-2014 04:09 PM
Super User
Posts: 3,252

Re: Graceful ways to handle missing data from a Proc Import of .xls files

Posted in reply to BenConner

You could try a LIBNAME statement with the EXCEL option. When you assign your LIBNAME to a workbook, all of the tabs will be listed in a PROC CONTENTS of the library. You could also use the EXIST function to test if a tab is present or not.

Regular Contributor
Posts: 179

Re: Graceful ways to handle missing data from a Proc Import of .xls files

Of course.  Then I can get direct access to what they -really- used for tab names and conditionally execute the transform/append steps.  And no nastygrams in the log files! Smiley Happy

Much appreciated!

--Ben

Regular Contributor
Posts: 179

Re: Graceful ways to handle missing data from a Proc Import of .xls files

As a followup, is there a way to disable SAS looking for field names on the first line of the spreadsheet in the "Libname Excel ..." approach?  It picked up a title and none of the columns have reasonable data for fieldnames.

Thanks!

--Ben

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 190 views
  • 0 likes
  • 2 in conversation