<?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: Get names of all excel files from multiple folders in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871973#M344491</link>
    <description>&lt;P&gt;What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; explained above might look like as below in code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsxlist pipe 'dir /b /s "C:\Users\Myfolders\*.xlsx" ';
data temp;
   infile xlsxlist truncover;
   input file_path_name $200.;
   file_name= scan(file_path_name, -1, '\');
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tested. Works fine for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2023 18:47:55 GMT</pubDate>
    <dc:creator>A_Kh</dc:creator>
    <dc:date>2023-04-25T18:47:55Z</dc:date>
    <item>
      <title>Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871953#M344482</link>
      <description>I have multiple folder on my C drive. Within each folder, I have one or two excel files. How can I find out all the names of folders and the excel files names? &lt;BR /&gt;&lt;BR /&gt;I wanted to use a macro to read those excel files into sas -how can accomplish ? Thank you.</description>
      <pubDate>Tue, 25 Apr 2023 17:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871953#M344482</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-25T17:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871956#M344483</link>
      <description>&lt;P&gt;Easiest would be the Windows DIR command such as open a Windows command window and type:&lt;/P&gt;
&lt;P&gt;Dir /S/B C:\*.xlsx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to create a TEXT file to hold that output add a &amp;gt;&amp;lt;path&amp;gt;\myfile.txt&lt;/P&gt;
&lt;P&gt;at the end or similar:&lt;/P&gt;
&lt;P&gt;Dir /S/B C:\*.xlsx &amp;gt; c:\folder\myfile.txt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The /S option on the command is search subfolders, so starting at C: it will search every folder on your drive. The /B option just lists the folder/file name information. The * is a wildcard for any file name with the given extension. If you have older XLS files as well as XLSX you would be best off by making two separate output files unless you are familiar with the Windows command line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your SAS is not server based you likely could use that as a PIPE in a filename but if your SAS is server based it likely doesn't see your hard drive to do such.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 17:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871956#M344483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-25T17:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871973#M344491</link>
      <description>&lt;P&gt;What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; explained above might look like as below in code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsxlist pipe 'dir /b /s "C:\Users\Myfolders\*.xlsx" ';
data temp;
   infile xlsxlist truncover;
   input file_path_name $200.;
   file_name= scan(file_path_name, -1, '\');
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tested. Works fine for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 18:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871973#M344491</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-25T18:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871981#M344492</link>
      <description>Thank you. I have the desktop version sas 9.4. Could you help with the sas code? Thanks again</description>
      <pubDate>Tue, 25 Apr 2023 18:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871981#M344492</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-25T18:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871993#M344497</link>
      <description>&lt;P&gt;I would set the length of the variable to at least 256, which I think is the maximum path and filename that windows supports to avoid truncation of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warning: if you have ONE-Drive installed, which typically places access in C:\users then you may be pulling names from cloud storage and not your local drive. I don't know about any other cloud services.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 19:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/871993#M344497</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-25T19:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/872035#M344505</link>
      <description>Sorry what is “Dir”? My path is as follow C://documents/data/… &lt;BR /&gt;After this “data”, I have many sub folders with excel files</description>
      <pubDate>Tue, 25 Apr 2023 21:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/872035#M344505</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-25T21:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/872059#M344511</link>
      <description>&lt;P&gt;Dir is a unix command. You can instead use a pre-written macro to get the list of files that you will then need to likely filter to what you want to import. Chantge the first path in the %dirtree below to be your path and run the program. Note that I've set it to run/search only to a depth of 10 folders deep. If you want it go further change the maxdepth parameter. It will create a table called filelist that will have a list of the files/folders.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dirtree url 
    'https://raw.githubusercontent.com/sasutils/macros/master/dirtree.sas';
%include dirtree /source2;
%dirtree(C:\documents\data\   /* Pipe delimited directory list (default=.) */
        , out=filelist  /* Output dataset name */
        , maxdepth=10 /* Maximum tree depth */);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will contain the list of all files and folders. You can then use a data step to filter out the files that only have the xlsx extension.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data excel_file_list;
set filelist;
where type = 'F';
*test that this works,if it does uncomment the line below to filter only xlsx files;
ext = reverse(scan(reverse(filename), 1, "."));
*if ext = 'xlsx';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry what is “Dir”? My path is as follow C://documents/data/… &lt;BR /&gt;After this “data”, I have many sub folders with excel files&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 22:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/872059#M344511</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-25T22:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get names of all excel files from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/955871#M373292</link>
      <description>&lt;P&gt;Many many thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 07:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-names-of-all-excel-files-from-multiple-folders/m-p/955871#M373292</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2025-01-13T07:07:30Z</dc:date>
    </item>
  </channel>
</rss>

