<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Check if a worksheet exists in an excel file in Microsoft Integration with SAS</title>
    <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50673#M746</link>
    <description>You may be able to use this program or some variation.  It creates a SAS data set of the name of all sheet in the XLS specified by the WORKBOOK fileref.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename workbook "path to xls of interest";&lt;BR /&gt;
data work.sheets;&lt;BR /&gt;
   length path script filevar command $256;&lt;BR /&gt;
   path     = pathname('WORKBOOK');&lt;BR /&gt;
   script   = catx('\',pathname('WORK'),'SHEETNAMESS.vbs');&lt;BR /&gt;
   filevar  = script;&lt;BR /&gt;
&lt;BR /&gt;
   /* write the script */&lt;BR /&gt;
   file dummy1 filevar=filevar;&lt;BR /&gt;
&lt;BR /&gt;
   put 'Const ' path=:$quote256.;&lt;BR /&gt;
   put 'Set objExcel = CreateObject("Excel.Application")';&lt;BR /&gt;
   put 'With objExcel';&lt;BR /&gt;
   put +3 '.Visible = False';&lt;BR /&gt;
   put +3 '.DisplayAlerts = False';&lt;BR /&gt;
   put +3 'Set objWorkbook  = .Workbooks.Open(path)';&lt;BR /&gt;
   put +3 'Set colSheets = .Worksheets';&lt;BR /&gt;
   put +3 'For Each objSheet In colSheets';&lt;BR /&gt;
   put +6    'WScript.echo objsheet.name';&lt;BR /&gt;
   put +6    'Next';&lt;BR /&gt;
   put +3 '.Application.Quit';&lt;BR /&gt;
   put +3 'End With';&lt;BR /&gt;
   &lt;BR /&gt;
   /* close the script file by opening another, not used */&lt;BR /&gt;
   filevar = catx('\',pathname('WORK'),'DUMMY.vbs');&lt;BR /&gt;
   file dummy1 filevar=filevar;&lt;BR /&gt;
&lt;BR /&gt;
   /* look at the script, not necessary but may be useful */&lt;BR /&gt;
   infile dummy2 filevar=script end=eof;&lt;BR /&gt;
   do _n_ = 1 by 1 until(eof);&lt;BR /&gt;
      input;&lt;BR /&gt;
      putlog _n_ z3. +1 _infile_;&lt;BR /&gt;
      end;&lt;BR /&gt;
&lt;BR /&gt;
   /* call the script */&lt;BR /&gt;
   command = catx(' ','cscript //nologo',quote(strip(script)));&lt;BR /&gt;
   infile dummy3 pipe filevar=command end=eof length=l;&lt;BR /&gt;
   do until(eof);&lt;BR /&gt;
      input sheet $varying256. l;&lt;BR /&gt;
      output;&lt;BR /&gt;
      putlog _infile_;&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc contents order=varnum;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Mon, 20 Jul 2009 13:50:04 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2009-07-20T13:50:04Z</dc:date>
    <item>
      <title>Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50667#M740</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Does anyone know if it's easily possible to check for the existence of a worksheet in an Excel file based on its name ?&lt;BR /&gt;
&lt;BR /&gt;
I'd like to perform that check before executing each "Proc import" statement in order not to have any error message in my log file when the specified worksheet does not exist.&lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance for your help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Florent&lt;BR /&gt;
&lt;BR /&gt;
Note: the SAS version we use at the customer is the 8.02</description>
      <pubDate>Wed, 01 Jul 2009 10:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50667#M740</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2009-07-01T10:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50668#M741</link>
      <description>Try using the LIBNAME EXCEL engine (this might be a more convenient option than IMPORT, anyway) like:&lt;BR /&gt;
&lt;BR /&gt;
52   libname excel excel "&amp;amp;my_docs\excel\111temp.xls";&lt;BR /&gt;
NOTE: Libref EXCEL was successfully assigned as follows:&lt;BR /&gt;
      Engine:        EXCEL&lt;BR /&gt;
      Physical Name: \\company.com\users\bldg\userid\My_Documents\excel\111temp.xls&lt;BR /&gt;
53   proc sql noprint;&lt;BR /&gt;
54     create table excel1 as&lt;BR /&gt;
55       select libname,memname&lt;BR /&gt;
56         from dictionary.tables&lt;BR /&gt;
57         where libname = 'EXCEL';&lt;BR /&gt;
NOTE: Table WORK.EXCEL1 created, with 2 rows and 2 columns.&lt;BR /&gt;
&lt;BR /&gt;
58     quit;&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
59   data _null_;&lt;BR /&gt;
60     set excel1;&lt;BR /&gt;
61     put _all_;&lt;BR /&gt;
62   run;&lt;BR /&gt;
&lt;BR /&gt;
libname=EXCEL memname=Sheet1$ _ERROR_=0 _N_=1&lt;BR /&gt;
libname=EXCEL memname=Sheet2$ _ERROR_=0 _N_=2&lt;BR /&gt;
NOTE: There were 2 observations read from the data set WORK.EXCEL1.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
63   libname excel clear;&lt;BR /&gt;
NOTE: Libref EXCEL has been deassigned.</description>
      <pubDate>Thu, 02 Jul 2009 13:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50668#M741</guid>
      <dc:creator>advoss</dc:creator>
      <dc:date>2009-07-02T13:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50669#M742</link>
      <description>Hi Advoss,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for the answer/example.&lt;BR /&gt;
&lt;BR /&gt;
The problem is that I'm not able to use the Excel engine as the customer doesn't own the license (and they don't want it). Thus I have to use the "proc import" facility.&lt;BR /&gt;
&lt;BR /&gt;
I know very well how to use this statement but unfortunately it gives an error while trying to import a worksheet which doesn't exist in the Excel file. This is why I created this post: to ask the SAS experts if there is a way to check the existence of a worksheet's name before executing the import of data.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your help.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Florent</description>
      <pubDate>Fri, 03 Jul 2009 13:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50669#M742</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2009-07-03T13:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50670#M743</link>
      <description>Share the code you are using and the exact SAS error from the log - that will help with debugging your problem.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 03 Jul 2009 13:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50670#M743</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-03T13:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50671#M744</link>
      <description>Here it is. This is a typical error message when the sheet you try to import does not exist in the Excel file.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
MPRINT(MAIN):  ;&lt;BR /&gt;
MPRINT(IMPORT_SHEET):   PROC IMPORT DATAFILE=&lt;BR /&gt;
"W:\04_0004\06_PRICING_CONTRACTING\05_STANDARDISED_ELEC\08_Airport_GUI\01_Dossiers\0100000-0120000\100002_TESTS_BETA_COPY\2009\SCEN_PTC01_090611-1710_0702-1348.XLS" OUT= efm_input_month_MV&lt;BR /&gt;
DBMS=EXCEL2000 REPLACE;&lt;BR /&gt;
MPRINT(IMPORT_SHEET):   AEXC;&lt;BR /&gt;
MPRINT(IMPORT_SHEET):   SHEET="Beta_INS_MV";&lt;BR /&gt;
MPRINT(IMPORT_SHEET):   GETNAMES=YES;&lt;BR /&gt;
MPRINT(IMPORT_SHEET):   RUN;&lt;BR /&gt;
&lt;BR /&gt;
ERROR 22-322: Expecting a name.&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
ERROR: Import unsuccessful.  See SAS Log for details.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: PROCEDURE IMPORT used:&lt;BR /&gt;
      real time           0.17 seconds&lt;BR /&gt;
      cpu time            0.07 seconds</description>
      <pubDate>Fri, 03 Jul 2009 16:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50671#M744</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2009-07-03T16:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50672#M745</link>
      <description>If you are getting a syntax error when the sheet does not exist, I would consider this an item for SAS tech support and recommend you open a track on the support site.  There should be some type of option you can set to control the level of error/warning raised in this condition.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 03 Jul 2009 17:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50672#M745</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-03T17:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50673#M746</link>
      <description>You may be able to use this program or some variation.  It creates a SAS data set of the name of all sheet in the XLS specified by the WORKBOOK fileref.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename workbook "path to xls of interest";&lt;BR /&gt;
data work.sheets;&lt;BR /&gt;
   length path script filevar command $256;&lt;BR /&gt;
   path     = pathname('WORKBOOK');&lt;BR /&gt;
   script   = catx('\',pathname('WORK'),'SHEETNAMESS.vbs');&lt;BR /&gt;
   filevar  = script;&lt;BR /&gt;
&lt;BR /&gt;
   /* write the script */&lt;BR /&gt;
   file dummy1 filevar=filevar;&lt;BR /&gt;
&lt;BR /&gt;
   put 'Const ' path=:$quote256.;&lt;BR /&gt;
   put 'Set objExcel = CreateObject("Excel.Application")';&lt;BR /&gt;
   put 'With objExcel';&lt;BR /&gt;
   put +3 '.Visible = False';&lt;BR /&gt;
   put +3 '.DisplayAlerts = False';&lt;BR /&gt;
   put +3 'Set objWorkbook  = .Workbooks.Open(path)';&lt;BR /&gt;
   put +3 'Set colSheets = .Worksheets';&lt;BR /&gt;
   put +3 'For Each objSheet In colSheets';&lt;BR /&gt;
   put +6    'WScript.echo objsheet.name';&lt;BR /&gt;
   put +6    'Next';&lt;BR /&gt;
   put +3 '.Application.Quit';&lt;BR /&gt;
   put +3 'End With';&lt;BR /&gt;
   &lt;BR /&gt;
   /* close the script file by opening another, not used */&lt;BR /&gt;
   filevar = catx('\',pathname('WORK'),'DUMMY.vbs');&lt;BR /&gt;
   file dummy1 filevar=filevar;&lt;BR /&gt;
&lt;BR /&gt;
   /* look at the script, not necessary but may be useful */&lt;BR /&gt;
   infile dummy2 filevar=script end=eof;&lt;BR /&gt;
   do _n_ = 1 by 1 until(eof);&lt;BR /&gt;
      input;&lt;BR /&gt;
      putlog _n_ z3. +1 _infile_;&lt;BR /&gt;
      end;&lt;BR /&gt;
&lt;BR /&gt;
   /* call the script */&lt;BR /&gt;
   command = catx(' ','cscript //nologo',quote(strip(script)));&lt;BR /&gt;
   infile dummy3 pipe filevar=command end=eof length=l;&lt;BR /&gt;
   do until(eof);&lt;BR /&gt;
      input sheet $varying256. l;&lt;BR /&gt;
      output;&lt;BR /&gt;
      putlog _infile_;&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc contents order=varnum;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 20 Jul 2009 13:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50673#M746</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-07-20T13:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50674#M747</link>
      <description>Florent&lt;BR /&gt;
&lt;BR /&gt;
as you may have found out by now, if your client does not license SAS/Access(r) Interface to PC File Formats (which would enable the excel libname engine), then it is very unlikely that you can run proc import with any variant of dbms=excel&lt;BR /&gt;
  &lt;BR /&gt;
unless you know different&lt;BR /&gt;
  &lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 21 Jul 2009 20:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50674#M747</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-07-21T20:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50675#M748</link>
      <description>data _null_;,&lt;BR /&gt;
&lt;BR /&gt;
After having made some changes (related to the SAS version that we use at the customer), I've tried to execute your example but it gives the following error.&lt;BR /&gt;
&lt;BR /&gt;
Would it be possible that I have this error message because of the SAS version ? What could I use in order to get the same result ? Could you briefly explain me the aim of that 'pipe' option (I'm not used to such customization of the infile statement) ?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PeterC,&lt;BR /&gt;
&lt;BR /&gt;
I've tried with other variants of the dbms option but this does not change anything.&lt;BR /&gt;
I still have an error message in the logfile if the sheet that I try to import does not exist in the Excel file.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks to both of you for your time.&lt;BR /&gt;
&lt;BR /&gt;
Kind Regards,&lt;BR /&gt;
Florent&lt;BR /&gt;
&lt;BR /&gt;
441  filename workbook "...\SCEN_PTC01_090611-1710_0714-1424.xls";&lt;BR /&gt;
&lt;BR /&gt;
442  data work.sheets;&lt;BR /&gt;
443     length path script filevar command $256;&lt;BR /&gt;
444     path     = pathname('WORKBOOK');&lt;BR /&gt;
445     script   = pathname('WORK')||'\SHEETNAMESS.vbs';&lt;BR /&gt;
446     filevar  = script;&lt;BR /&gt;
447&lt;BR /&gt;
448     /* write the script */&lt;BR /&gt;
449     file dummy1 filevar=filevar;&lt;BR /&gt;
450&lt;BR /&gt;
451     put 'Const ' path=:$quote256.;&lt;BR /&gt;
452     put 'Set objExcel = CreateObject("Excel.Application")';&lt;BR /&gt;
453     put 'With objExcel';&lt;BR /&gt;
454     put +3 '.Visible = False';&lt;BR /&gt;
455     put +3 '.DisplayAlerts = False';&lt;BR /&gt;
456     put +3 'Set objWorkbook  = .Workbooks.Open(path)';&lt;BR /&gt;
457     put +3 'Set colSheets = .Worksheets';&lt;BR /&gt;
458     put +3 'For Each objSheet In colSheets';&lt;BR /&gt;
459     put +6    'WScript.echo objsheet.name';&lt;BR /&gt;
460     put +6    'Next';&lt;BR /&gt;
461     put +3 '.Application.Quit';&lt;BR /&gt;
462     put +3 'End With';&lt;BR /&gt;
463&lt;BR /&gt;
464     /* close the script file by opening another, not used */&lt;BR /&gt;
465     filevar = pathname('WORK')||'DUMMY.vbs';&lt;BR /&gt;
466     file dummy1 filevar=filevar;&lt;BR /&gt;
467&lt;BR /&gt;
468     /* look at the script, not necessary but may be useful */&lt;BR /&gt;
469     infile dummy2 filevar=script end=eof;&lt;BR /&gt;
470     do _n_ = 1 by 1 until(eof);&lt;BR /&gt;
471        input;&lt;BR /&gt;
472        put _n_ z3. +1 _infile_;&lt;BR /&gt;
473        end;&lt;BR /&gt;
474&lt;BR /&gt;
475     /* call the script */&lt;BR /&gt;
476     command = 'cscript //nologo '||quote(trimn(left(script)));&lt;BR /&gt;
NOTE: SCL source line.&lt;BR /&gt;
477     infile dummy3 pipe filevar=command end=eof length=l;&lt;BR /&gt;
                      ----&lt;BR /&gt;
                      23&lt;BR /&gt;
ERROR 23-2: Invalid option name PIPE.&lt;BR /&gt;
&lt;BR /&gt;
478     do until(eof);&lt;BR /&gt;
479        input sheet $varying256. l;&lt;BR /&gt;
480        output;&lt;BR /&gt;
481        put _infile_;&lt;BR /&gt;
482        end;&lt;BR /&gt;
483     stop;&lt;BR /&gt;
484     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
WARNING: The data set WORK.SHEETS may be incomplete.  When this step was stopped there were 0 observations and 2 variables.&lt;BR /&gt;
WARNING: Data set WORK.SHEETS was not replaced because this step was stopped.&lt;BR /&gt;
NOTE: DATA statement used:&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds</description>
      <pubDate>Wed, 22 Jul 2009 12:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50675#M748</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2009-07-22T12:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a worksheet exists in an excel file</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50676#M749</link>
      <description>This program works with SAS 9.1.3 on Windows.  I don't know if it works in version 8.&lt;BR /&gt;
&lt;BR /&gt;
If PIPE does not work with FILEVAR in version 8 you can do the same thing with multiple data steps.</description>
      <pubDate>Wed, 22 Jul 2009 16:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Check-if-a-worksheet-exists-in-an-excel-file/m-p/50676#M749</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-07-22T16:07:11Z</dc:date>
    </item>
  </channel>
</rss>

