<?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: SAS Macro to Check Each Subfolder Within a Directory and Import Excel Files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/868955#M343276</link>
    <description>&lt;P&gt;Here's a macro that will scan a directory (and subdirectories) and list the files. Use that instead to list all the files and then you have the path and filenames.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Parse that output to get a list of files you want to import.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can import each file using the macro you wrote or dynamically using call execute, or a combination.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably more efficient if this isn't actually all under My Folder and in a separate directory where you'll have less false positives.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Apr 2023 21:44:19 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-04-10T21:44:19Z</dc:date>
    <item>
      <title>SAS Macro to Check Each Subfolder Within a Directory and Import Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/868953#M343275</link>
      <description>&lt;P&gt;I'm trying to put together a SAS macro that will check each subfolder within a directory and import the Excel spreadsheets if they exist.&lt;/P&gt;&lt;P&gt;The directory path is structured by the current month name and year. I am able to define that with the %curr_month_path macro variables below, so I'm good there.&lt;/P&gt;&lt;PRE&gt;%let dt = today();
%let folder_path = 'c:\My Folder';
%let curr_month_name = strip(put(&amp;amp;dt, monname.));
%let curr_month_year = year(&amp;amp;dt);
%let curr_month_path = catx('\', &amp;amp;folder_path, catx(' ', &amp;amp;curr_month_name, &amp;amp;curr_month_year));&lt;/PRE&gt;&lt;P&gt;Within the monthly folder/directory, there are individual subfolders for each day of the month example: "4 1 2023", "4 2 2023" etc. and within each of the daily folders there are a possibility of containing two Excel files.&lt;/P&gt;&lt;P&gt;I'd like to loop through each of the subfolders to check to see if a an .xlsx file that starts with the word "Invoice" exists and then import that file.&lt;/P&gt;&lt;P&gt;At it's simplest form, I do have a macro below that will import one of the spreadsheets for reference, I would just need to dynamically check each folder to import the files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro nw;
   proc import out=t_import(rename=("Source Case #"n=case_number) keep="Source Case #"n)
   datafile="c:\My Folder\Invoice File 123.xlsx"
   dbms=xlsx
   replace;
 run;
%mend nw;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Apr 2023 21:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/868953#M343275</guid>
      <dc:creator>nbwest76</dc:creator>
      <dc:date>2023-04-10T21:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to Check Each Subfolder Within a Directory and Import Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/868955#M343276</link>
      <description>&lt;P&gt;Here's a macro that will scan a directory (and subdirectories) and list the files. Use that instead to list all the files and then you have the path and filenames.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Parse that output to get a list of files you want to import.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can import each file using the macro you wrote or dynamically using call execute, or a combination.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably more efficient if this isn't actually all under My Folder and in a separate directory where you'll have less false positives.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 21:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/868955#M343276</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-10T21:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to Check Each Subfolder Within a Directory and Import Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/869087#M343311</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Assuming you are using Windows OS
and could invoke OS command via SAS.
*/
%let dir=  c:\temp  ;




options validmemname=extend;
filename x pipe %sysfunc(quote(dir "&amp;amp;dir\*.xlsx" /s /b));
data _null_;
infile x ;
input ;
call execute(catt('proc import datafile="',_infile_,'" 
 out=',compress(scan(_infile_,-2,'\.'),,'kda'),' dbms=xlsx replace;run;' ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Apr 2023 11:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/869087#M343311</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-04-11T11:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro to Check Each Subfolder Within a Directory and Import Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/869878#M343603</link>
      <description>Exactly what I was looking for, thanks!</description>
      <pubDate>Fri, 14 Apr 2023 18:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-and-Import/m-p/869878#M343603</guid>
      <dc:creator>nbwest76</dc:creator>
      <dc:date>2023-04-14T18:35:30Z</dc:date>
    </item>
  </channel>
</rss>

