<?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: Import multiple excel files where in some dates files don't exist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424523#M281052</link>
    <description>&lt;P&gt;Do you have command line access?&amp;nbsp; If so use a directory listing to only import those given files:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "c:/yourlocation/*.xlsx" /b';

data _null_;
  infile tmp;
  input;
  call execute(cats('%Import_XLSX (fname=',_infile_,');'));
run;&lt;/PRE&gt;
&lt;P&gt;This will (on windows, unix is slightly different) call a directory listing and for each filename recieved call a macro call Import_XLSX with the file in question.&amp;nbsp; This way you don't need to know what is there (i.e. date ranges etc.).&amp;nbsp; You can do the same with SAS fopen and such like commands also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem here really is the use of Excel and the Excel thinking behind it for instance&amp;nbsp;none of this would be an issue if it wasn't for the need to put data in filenames...&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2018 09:36:43 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-03T09:36:43Z</dc:date>
    <item>
      <title>Import multiple excel files where in some dates files don't exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424515#M281050</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;My task at work is to import multiple Excel files into SAS .&lt;/P&gt;&lt;P&gt;Each excel file that I import will be a SAS data set.&lt;/P&gt;&lt;P&gt;The Excel files are a daily files that started from 01012017(01Jan2017) until 31122017(31Dec2017).&lt;/P&gt;&lt;P&gt;I crrated a vector of dates from&amp;nbsp;&lt;SPAN&gt;01012017 &amp;nbsp;until&amp;nbsp;31122017 &amp;nbsp;and run a macro to import the excel files.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The problem is that there are dates that there is no excel file and then I get an error while I run the import Macro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What do you offer to do?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a way to tell sas that if it dosen't find the excel file then don't send an error and just create an empty file?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a way to tell SAS &amp;nbsp;to import excel files only for existing dates?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ron&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 07:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424515#M281050</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-01-03T07:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple excel files where in some dates files don't exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424519#M281051</link>
      <description>&lt;P&gt;Use the fexist() function to determine if a file is present, and make your import step dependent on this.&lt;/P&gt;
&lt;P&gt;eg&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro your_macro;

/* filename is determined here */

data _null_;
if fexist("&amp;amp;filename")
then call symput('file_present','yes');
else call symput('file_present','no');
run;

%if &amp;amp;file_present = yes
%then %do;

/* import */

%end;
%else %do;

/* data step that creates an empty file with correct variables */

%end;

/* further processing */

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2018 08:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424519#M281051</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-03T08:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple excel files where in some dates files don't exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424523#M281052</link>
      <description>&lt;P&gt;Do you have command line access?&amp;nbsp; If so use a directory listing to only import those given files:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "c:/yourlocation/*.xlsx" /b';

data _null_;
  infile tmp;
  input;
  call execute(cats('%Import_XLSX (fname=',_infile_,');'));
run;&lt;/PRE&gt;
&lt;P&gt;This will (on windows, unix is slightly different) call a directory listing and for each filename recieved call a macro call Import_XLSX with the file in question.&amp;nbsp; This way you don't need to know what is there (i.e. date ranges etc.).&amp;nbsp; You can do the same with SAS fopen and such like commands also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem here really is the use of Excel and the Excel thinking behind it for instance&amp;nbsp;none of this would be an issue if it wasn't for the need to put data in filenames...&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 09:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-excel-files-where-in-some-dates-files-don-t/m-p/424523#M281052</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-03T09:36:43Z</dc:date>
    </item>
  </channel>
</rss>

