<?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 excel files into sas from dates in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728006#M226517</link>
    <description>&lt;P&gt;Suppose you have a macrio to import a single file, something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do date = today() - 8 to today() - 1;
  datestr = put(date,ddmmyyn8.);
  if fileexist(cats("&amp;amp;path./t",datestr,".xlsx"))
  then call execute('%nrstr(%excel_import("!!(cats("&amp;amp;path./t",datestr,".xlsx"))!!'))');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Modify the CALL EXECUTE as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW why do you use the unfavorable DMY date order? Dates in YMD order are much easier to handle.&lt;/P&gt;</description>
    <pubDate>Sun, 21 Mar 2021 13:57:11 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-21T13:57:11Z</dc:date>
    <item>
      <title>import excel files into sas from dates in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/727987#M226506</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have excel files called tDDMMYYYY .&lt;/P&gt;
&lt;P&gt;for example: t14032021 ,t15032021 and so on&lt;/P&gt;
&lt;P&gt;I want to import them into SAS from 7 days before yesterday until yesterday.&lt;/P&gt;
&lt;P&gt;I created a data set that including a column&amp;nbsp;&lt;CODE class=" language-sas"&gt;date_char &amp;nbsp;with&amp;nbsp;required&amp;nbsp;potential&amp;nbsp;excel&amp;nbsp;files&amp;nbsp;that&amp;nbsp;need&amp;nbsp;to&amp;nbsp;import&amp;nbsp;into&amp;nbsp;SAS.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Some of the excel files might not exist.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What&amp;nbsp;is&amp;nbsp;the&amp;nbsp;way&amp;nbsp;to&amp;nbsp;create&amp;nbsp;a&amp;nbsp;dynamic&amp;nbsp;import&amp;nbsp;into&amp;nbsp;sas&amp;nbsp;of&amp;nbsp;these&amp;nbsp;excel&amp;nbsp;files&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thanks&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lastDay_SAS=%sysfunc(intnx(day,%sysfunc(today()),-1,same));
%put &amp;amp;=lastDay_SAS;
%let minus7_SAS=%sysfunc(intnx(day,%sysfunc(today()),-8,same));
%put &amp;amp;=minus7_SAS;

data want_days(keep=date_char);
date=&amp;amp;minus7_SAS.;
date_char=put(date,DDMMYYn8.);
end_date=&amp;amp;lastDay_SAS.;
do while (date&amp;lt;=end_date);
output;
date=intnx('day', date, 1, 's');
date_char=put(date,DDMMYYn8.);
format date DDMMYYn8.;
end;
run;

Now&amp;nbsp;need&amp;nbsp;to&amp;nbsp;import&amp;nbsp;excel&amp;nbsp;files&amp;nbsp;:&lt;BR /&gt;t13032021&lt;BR /&gt;t14032021&lt;BR /&gt;t15032021&lt;BR /&gt;t16032021&lt;BR /&gt;t17032021&lt;BR /&gt;t18032021&lt;BR /&gt;t19032021&lt;BR /&gt;t20032021&lt;BR /&gt;It&amp;nbsp;might&amp;nbsp;happen&amp;nbsp;that&amp;nbsp;some&amp;nbsp;of&amp;nbsp;the&amp;nbsp;excel&amp;nbsp;files&amp;nbsp;doesnt&amp;nbsp;exist&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Mar 2021 09:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/727987#M226506</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-21T09:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: import excel files into sas from dates in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728002#M226513</link>
      <description>&lt;P&gt;Create the Full path and name of the file.&lt;/P&gt;
&lt;P&gt;Use the FEXIST function to determine if the file exists. &lt;BR /&gt;If it does not exist then don't add it to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really, you want to &lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;import excel files :t13032021t14032021t15032021t16032021t17032021t18032021t19032021t20032021&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I don't know how you make that string but you really need to consider what you did.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Mar 2021 12:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728002#M226513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-21T12:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: import excel files into sas from dates in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728006#M226517</link>
      <description>&lt;P&gt;Suppose you have a macrio to import a single file, something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do date = today() - 8 to today() - 1;
  datestr = put(date,ddmmyyn8.);
  if fileexist(cats("&amp;amp;path./t",datestr,".xlsx"))
  then call execute('%nrstr(%excel_import("!!(cats("&amp;amp;path./t",datestr,".xlsx"))!!'))');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Modify the CALL EXECUTE as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW why do you use the unfavorable DMY date order? Dates in YMD order are much easier to handle.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Mar 2021 13:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728006#M226517</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-21T13:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: import excel files into sas from dates in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728010#M226520</link>
      <description>&lt;P&gt;Use FILEEXIST() function to test if the XLSX file exists.&lt;/P&gt;
&lt;P&gt;Use iterative do loop when iterating over integers.&lt;/P&gt;
&lt;P&gt;Use CALL EXECUTE() to generate code from data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_days ;
  length date 8 member $32 fname $200;
  format date date9.;
  do date = today()-8 to today()-1 ;
    member = 't'||put(date,ddmmyyn8.);
    fname=cats("&amp;amp;path/",member,'.xlsx');
    if fileexist(fname) then do;
       output;
       call execute(catx(' '
              ,'proc import datafile=',quote(trim(fname))
              ,'dbms=xlsx'
              ,'out=',member,'replace'
              ,';run;'
       ));
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Mar 2021 16:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-files-into-sas-from-dates-in-data-set/m-p/728010#M226520</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-21T16:16:03Z</dc:date>
    </item>
  </channel>
</rss>

