<?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: How to: List all the files in a folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717767#M222020</link>
    <description>&lt;P&gt;Peter,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I thought that you were just using this technique to get the filenames.&amp;nbsp; You could forgo the variables and just use INPUT ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pdf_files ;

  length file 
         filename $ 256
          ;

  infile "C:\Users\kviel\Documents\My SAS Files\9.4\Documentation\*.pdf" 
         filename = file
         eov = eov
         ;

  input ;

  filename = file ;

  if    _n_ = 1
     or eov = 1
  then 
    do ; 
       output ;
       eov = 0 ;
    end ;

run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is not recursive and, unless one is CERTAIN that the folder contains no child folder, then it reads only files of the specified extension.&amp;nbsp; I toyed with the MEMVAR= option, but I ran out of time.&amp;nbsp; I am not even sure if that is the right direction.&amp;nbsp; Again, this reads every record of every file, so it is not as efficient as Kurt's suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 00:28:04 GMT</pubDate>
    <dc:creator>Kevin_Viel</dc:creator>
    <dc:date>2021-02-09T00:28:04Z</dc:date>
    <item>
      <title>How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674065#M202918</link>
      <description>&lt;P&gt;Hi, I am using SAS University Edition and trying to get names of all the file available in a Folder (Folder inside Shared Folder). So that, I can prepared a Macro to import and append all the data sets in one.&amp;nbsp;&lt;BR /&gt;I need help to get names for all the CSV files available in my Folder.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 02:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674065#M202918</guid>
      <dc:creator>MS_Bhati</dc:creator>
      <dc:date>2020-12-21T02:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674066#M202919</link>
      <description>&lt;P&gt;This question has been asked over and over. Maybe this topic should be a sticky &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33307"&gt;@AnnaBrown&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34537"&gt;@BeverlyBrown&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Search&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;list files&amp;nbsp;&lt;/FONT&gt; &amp;nbsp;for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Out of many replies, here is a clever way, devised by Tom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FILELIST;
  format DIR LEVEL 3. PATH FILENAME $256. LASTMOD datetime.;
  retain DIR 0 LEVEL -1 FILENAME ' ' LASTMOD .;
  input PATH;
cards;
c:\temp\
x:\ 
run;
data FILELIST;
  retain SEP "%sysfunc(ifc(&amp;amp;sysscp=WIN,\,/))";
  modify FILELIST;
  RC    = filename('tmp',catx(SEP, PATH, FILENAME));
  DIRID = dopen('tmp');
  DIR   = (DIRID&amp;gt;0);
  if DIR then do;
    PATH     = catx(SEP, PATH, FILENAME);
    FILENAME = ' ';
    if SEP='/' then LASTMOD  = input(dinfo(DIRID, doptname(DIRID, 5)), nldatm100.);
    replace;
    DIR  =0;
    LEVEL=LEVEL+1;
    do I=1 to dnum(DIRID);
      FILENAME=dread(DIRID, I);
      output;
    end;
    RC=dclose(DIRID);
  end;
  else if scan(FILENAME,-1,'.') ne 'lck' then do;
    FID=fopen('tmp','i',0,'b');
    %* == FOPTNAME values for single files ==
         Unix                Win
    1  Filename            Filename
    2  Owner name          RECFM
    3  Group name          LRECL
    4  Access Permission   File Size (bytes)
    5  Last Modified       Last Modified
    6  File Size (bytes)   Create Time      ;
    if FID  then do;
      LASTMOD = input(finfo(FID, foptname(FID, 5)), nldatm100.);
      SIZE    = input(finfo(FID, foptname(FID, ifn(SEP='/',6,4))), 32.);
      RC      = fclose(FID);
      replace;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 08:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674066#M202919</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-08-03T08:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674067#M202920</link>
      <description>&lt;P&gt;Use the built-in SAS functions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
length fref $8 fname $200;
did = filename(fref,'/folders/myfolders');
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  output;
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Aug 2020 08:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/674067#M202920</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-03T08:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/691455#M210461</link>
      <description>&lt;P&gt;Yet another approach...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/dirlist.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/dirlist.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 05:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/691455#M210461</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2020-10-14T05:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to: Listing all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/702710#M215240</link>
      <description>&lt;P&gt;You can also see an example from SAS Documentation , a dynamic way of doing this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n0js70lrkxo6uvn1fl4a5aafnlgt.htm&amp;amp;locale=en" target="_self"&gt;A Macro which gets you Sub Dir and File Names&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
%local filrf rc did memcnt name i;
%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
%let did=%sysfunc(dopen(&amp;amp;filrf));

%if &amp;amp;did eq 0 %then %do; 
%put Directory &amp;amp;dir cannot be open or does not exist;
%return;
%end;

%do i = 1 %to %sysfunc(dnum(&amp;amp;did));

%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
%put &amp;amp;dir\&amp;amp;name;
%end;
%else %if %qscan(&amp;amp;name,2,.) = %then %do; 
%list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
%end;

%end;
%let rc=%sysfunc(dclose(&amp;amp;did));
%let rc=%sysfunc(filename(filrf));

%mend list_files;
%list_files(c:\temp,sas)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 03:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/702710#M215240</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2020-12-01T03:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708190#M217582</link>
      <description>hi Kurt ,&lt;BR /&gt;&lt;BR /&gt;May you please explain me the above approach ??&lt;BR /&gt;thank you in advance</description>
      <pubDate>Fri, 25 Dec 2020 14:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708190#M217582</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-25T14:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708191#M217583</link>
      <description>&lt;P&gt;It first creates a file reference for the directory (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n15scht124hr4nn1g296cqg2kqfa.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FILENAME&lt;/A&gt;), opens the directory and creates a handle (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0hpa8p9kacbran1ndqiw3krwohq.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;DOPEN&lt;/A&gt;), and then loops over all (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0m5yzvai5v9phn1gsdca9j6utzw.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;DNUM&lt;/A&gt;) entries in the directory and reads each (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1u8n0tue0ymkrn109xu8ya01kle.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;DREAD&lt;/A&gt;). At the end, it deassigns the handle and the file reference.&lt;/P&gt;
&lt;P&gt;I recommend studying the documentation of all these functions.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2020 15:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708191#M217583</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-25T15:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708927#M217901</link>
      <description>&lt;P&gt;I wrote a macro that allows recursive functionality and adds FINFO data.&amp;nbsp; This works on both Windows and Linux, even when the X statement cannot be used.&amp;nbsp; On LSAF, the datetime stamps are moot since the file is copied to the transient directory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 17:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708927#M217901</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2020-12-31T17:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708928#M217902</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361764"&gt;@Kevin_Viel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I wrote a macro that allows recursive functionality and adds FINFO data.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You're not the first one &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 18:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708928#M217902</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-31T18:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708930#M217904</link>
      <description>&lt;P&gt;No doubt and I did not search, but it might make a suitable SUG paper if one does not already exist or does not have some functionalities.&amp;nbsp; I use it quite frequently.&amp;nbsp; I have read entire directories in minutes, which is fast given the structure and volume, but I am sure it could be faster.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 18:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708930#M217904</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2020-12-31T18:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need alternative of "Filename" statement with Pipe operator for SAS University Edition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708936#M217908</link>
      <description>&lt;P&gt;I would have presented it this year in Washington (was an invited speaker), but COVID ...&lt;/P&gt;
&lt;P&gt;Actually, a complete session about interacting with the base operating system, with and without XCMD.&lt;/P&gt;
&lt;P&gt;I plan it for the next in-person Global Forum.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 19:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/708936#M217908</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-31T19:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717459#M221881</link>
      <description>I know&lt;BR /&gt;It's been done (to death&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;)&lt;BR /&gt;But for such a simple request it's nice to provide the simple solution:&lt;BR /&gt;Read all csv files in one folder into one dataset.....&lt;BR /&gt;Data resultDS( compress= yes) ;&lt;BR /&gt;Length file filename col1-col100 $300 ;&lt;BR /&gt;INFILE  "yourfolder/?*.csv" lrecl= 32000 dsd  filename= file truncover ;&lt;BR /&gt;Input col1-col100 ;&lt;BR /&gt;Filename=file ;&lt;BR /&gt;Run ;&lt;BR /&gt;</description>
      <pubDate>Sun, 07 Feb 2021 23:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717459#M221881</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-02-07T23:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717573#M221931</link>
      <description>&lt;P&gt;That is a simple approach if the number of files is small and the file sizes are also small.&amp;nbsp; It is a good demonstration. For a single level, i.e. not recursive, Kurt snippet is a great approach.&amp;nbsp; Have you tried this with other file formats, life PDF?&amp;nbsp; I suspect it would still work.&amp;nbsp; I also wonder about using *.*?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 14:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717573#M221931</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2021-02-08T14:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717762#M222016</link>
      <description>Hi Kevin&lt;BR /&gt;Any extension of this simple routine should be cautious about handling binary files like .xlsx format. The simple precision of the DSD option in handling "xxxxx separated values" won't work for binary data. However, it only needs a DLM= '09'x added to the INFILE statement to switch to tab separated values. If there is acceptable standard that .csv files need DLM= ',' and .tsv files need DLM= '09'x then these could be dynamically supported in folders with a the mix of file types, because the DLM= value can name a variable which you change depending on the file type/extension. Timing takes care and probably, practise. My guess is the added complexity is not well rewarded.&lt;BR /&gt;By the way, the DLM= value can hold more than one character. These then are alternative delimiters. So, if tabs only appear   as delimiters in .csv files and likewise commas are protected (by quotes) when not to be treated as delimiters .... then the DLM could be that combination '2c09'x&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Feb 2021 22:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717762#M222016</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-02-08T22:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717767#M222020</link>
      <description>&lt;P&gt;Peter,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I thought that you were just using this technique to get the filenames.&amp;nbsp; You could forgo the variables and just use INPUT ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pdf_files ;

  length file 
         filename $ 256
          ;

  infile "C:\Users\kviel\Documents\My SAS Files\9.4\Documentation\*.pdf" 
         filename = file
         eov = eov
         ;

  input ;

  filename = file ;

  if    _n_ = 1
     or eov = 1
  then 
    do ; 
       output ;
       eov = 0 ;
    end ;

run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is not recursive and, unless one is CERTAIN that the folder contains no child folder, then it reads only files of the specified extension.&amp;nbsp; I toyed with the MEMVAR= option, but I ran out of time.&amp;nbsp; I am not even sure if that is the right direction.&amp;nbsp; Again, this reads every record of every file, so it is not as efficient as Kurt's suggestion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 00:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717767#M222020</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2021-02-09T00:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717812#M222046</link>
      <description>Hi Kevin&lt;BR /&gt;My suggestion was only for readkng contents of the files. I wouldn't use it for file names. However, with some scenarios (e.g. expecting only small files) your proposal works, but excludes empty files. I don't remember what happens for subfolders.&lt;BR /&gt;  &lt;BR /&gt;Peter&amp;nbsp;</description>
      <pubDate>Tue, 09 Feb 2021 08:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717812#M222046</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-02-09T08:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717817#M222050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15174"&gt;@Peter_C&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Kevin&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;My suggestion was only for readkng contents of the files. I wouldn't use it for file names&lt;/STRONG&gt;&lt;/FONT&gt;. However, with some scenarios (e.g. expecting only small files) your proposal works, but excludes empty files. I don't remember what happens for subfolders.&lt;BR /&gt;&lt;BR /&gt;Peter&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) If the red text above is correct, then your solution, while it works, isn't on topic.&amp;nbsp; Well, the code is on topic, just not your red text above. The subject was "List all the files in a folder".&lt;/P&gt;
&lt;P&gt;2) Even if the proposed code works, I just can't see how reading every line in a file just to get the filename is a good approach?&amp;nbsp; Sure, for small text files in a directory, it might even work faster than the SAS functions used in previous solutions - the data step is very fast at reading text files.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But put 100,000 1MB each XML or binary files in a directory and test the performance of the all the various solutions posted in this thread.&amp;nbsp; You don't know a priori the contents of the directory and can't assume its contents.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 09:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717817#M222050</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2021-02-09T09:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to: Listing all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717820#M222053</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14488"&gt;@LittlesasMaster&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can also see an example from SAS Documentation , a dynamic way of doing this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n0js70lrkxo6uvn1fl4a5aafnlgt.htm&amp;amp;locale=en" target="_self"&gt;A Macro which gets you Sub Dir and File Names&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
%local filrf rc did memcnt name i;
%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
%let did=%sysfunc(dopen(&amp;amp;filrf));

%if &amp;amp;did eq 0 %then %do; 
%put Directory &amp;amp;dir cannot be open or does not exist;
%return;
%end;

%do i = 1 %to %sysfunc(dnum(&amp;amp;did));

%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
%put &amp;amp;dir\&amp;amp;name;
%end;
%else %if %qscan(&amp;amp;name,2,.) = %then %do; 
%list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
%end;

%end;
%let rc=%sysfunc(dclose(&amp;amp;did));
%let rc=%sysfunc(filename(filrf));

%mend list_files;
%list_files(c:\temp,sas)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This macro looping would be orders of magnitude slower than using corresponding functions in a data step, although it does have the benefit of being recursive.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 09:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717820#M222053</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2021-02-09T09:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717821#M222054</link>
      <description>thanks Scott&lt;BR /&gt;Probably put it down to my ARADD&lt;BR /&gt;(age related attention deficit disorder)&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;</description>
      <pubDate>Tue, 09 Feb 2021 09:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717821#M222054</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-02-09T09:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to: List all the files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717907#M222085</link>
      <description>&lt;P&gt;Peter,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; It fails when a folder is present:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: Invalid file, C:\Users\kviel\Documents\My SAS Files\9.4\Documentation\New folder.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.PDF_FILES may be incomplete.  When this step was stopped there were 0 observations and 1 variables.
WARNING: Data set WORK.PDF_FILES was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 14:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-List-all-the-files-in-a-folder/m-p/717907#M222085</guid>
      <dc:creator>Kevin_Viel</dc:creator>
      <dc:date>2021-02-09T14:20:18Z</dc:date>
    </item>
  </channel>
</rss>

