<?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: Count the the number of files ( specific type ) in Folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842769#M333241</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&amp;nbsp;, It worked for what I am looking.&lt;/P&gt;
&lt;P&gt;Special thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; for taking your time and provide the valuable alternatives. I tried the your approach as well. Which do the same job as expected. I really thank you for all your time.&lt;/P&gt;</description>
    <pubDate>Sun, 06 Nov 2022 18:24:39 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-11-06T18:24:39Z</dc:date>
    <item>
      <title>Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842679#M333208</link>
      <description>&lt;P&gt;I want to count the number of files in specific folder and specific kind of files. How I can achieve it in efficient way. I am looking because depending on the count I need to run another macro.&amp;nbsp; In the image I mentioned&amp;nbsp; How my folder structure and also how I want a outputs ('account' is the major folder which have Two subfolders with 'Expense' and 'Profits' which contains files.)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1667666291170.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76983iE98C60F29CED48DA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1667666291170.png" alt="SASuserlot_1-1667666291170.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thank you for your inputs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data filenames_;
	length fref $8 fname $200;
	did = filename(fref,"c:\documents\accounts");
	did = dopen(fref);
/*	count=  dnum(did);*/
	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;
&lt;DIV id="tinyMceEditorSASuserlot_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842679#M333208</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-05T16:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842680#M333209</link>
      <description>&lt;P&gt;PROC FREQ can do this simple counting.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842680#M333209</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-05T16:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842682#M333210</link>
      <description>&lt;P&gt;Thanks, I will try that way, I have like hundreds of subfolders ( I thought Freq is not efficient) so, I am looking this way where it automatically goes to the path provided and counts the file number.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842682#M333210</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-05T16:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842685#M333211</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, I will try that way, I have like hundreds of subfolders ( I thought Freq is not efficient) so, I am looking this way where it automatically goes to the path provided and counts the file number.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you mean you want to subset the list of files to just those for a particular directory?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a dataset that like the one generated by this macro:&amp;nbsp;&amp;nbsp;&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;You could count how many files are directly in each directory in the tree by aggregating by the PATH variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what do you mean by TYPE?&amp;nbsp; Are you talking about the extension on the file?&amp;nbsp; You could create a variable that has just the extension part of the filename (the part after the last period).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set dirtree;
  if index(filename,'.') then extension=scan(filename,-1,'.');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then summarize by the extension in each directory.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=want;
  tables path*extension / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Nov 2022 17:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842685#M333211</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-05T17:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842686#M333212</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, I will try that way, I have like hundreds of subfolders ( I thought Freq is not efficient) so, I am looking this way where it automatically goes to the path provided and counts the file number.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FREQ is very efficient. And with "hundreds" of folders (as opposed to millions), its hard to imagine you'll find a noticeably faster way. Certainly you could do lots of coding and achieve small increases in speed.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 17:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842686#M333212</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-05T17:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842706#M333216</link>
      <description>&lt;P&gt;If option XCMD set then I find it coding wise often easier and "shorter" to use an OS command for recursive file listings. Below how this could look-like for Windows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.path_and_filename;
  infile 'dir "c:\documents\accounts\*" /B/S/A-D/ON' pipe truncover;
  input path_file $1000.;
  length path $1000 file_name $60 suffix $10.;
  path=substr(path_file,1,findc(path_file,'\',-1000)-1);
  file_name=scan(path_file,-1,'\');
  suffix=scan(path_file,-1,'.');
  if findc(suffix,'\') then call missing(suffix);
  /* restrict to certain suffixes */
  /*if lowcase(suffix) in ('sas','txt','csv');*/
run;

proc sql;
  create table counts as
  select 
    path,
    suffix,
    count(*) as n_files
  from work.path_and_filename
  group by
    path,
    suffix
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Nov 2022 01:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842706#M333216</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-11-06T01:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count the the number of files ( specific type ) in Folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842769#M333241</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&amp;nbsp;, It worked for what I am looking.&lt;/P&gt;
&lt;P&gt;Special thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; for taking your time and provide the valuable alternatives. I tried the your approach as well. Which do the same job as expected. I really thank you for all your time.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 18:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-the-number-of-files-specific-type-in-Folder/m-p/842769#M333241</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-06T18:24:39Z</dc:date>
    </item>
  </channel>
</rss>

