<?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: Recurse a Directory of CSV Files and get Row Counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/635010#M188515</link>
    <description>&lt;P&gt;Thank you everyone for your responses!&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2020 11:41:12 GMT</pubDate>
    <dc:creator>JeffreyLowe</dc:creator>
    <dc:date>2020-03-26T11:41:12Z</dc:date>
    <item>
      <title>Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634835#M188434</link>
      <description>&lt;P&gt;Greetings......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to loop through a folder of CSV files to get the number of rows from each file (excluding the header row) insert the file name and row count into an existing dataset and lastly delete the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File1 250&lt;/P&gt;&lt;P&gt;insert fname rowcount into CSVRowCounts&lt;/P&gt;&lt;P&gt;delete File 1&lt;/P&gt;&lt;P&gt;File2 95&lt;/P&gt;&lt;P&gt;insert fname rowcount into CSVRowCounts&lt;/P&gt;&lt;P&gt;delete File2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634835#M188434</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2020-03-25T17:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634838#M188437</link>
      <description>&lt;P&gt;If this is on Linux then in a terminal session I would cd to the folder in question and:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wc -l *.csv 1&amp;gt;csvRowCounts.txt&lt;/P&gt;
&lt;P&gt;rm -f *.csv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in SAS you can read csvRowCounts.txt into SAS and subtract 1 from each count.&amp;nbsp; But I wouldn't rm the files until you are sure of your result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634838#M188437</guid>
      <dc:creator>JerryV</dc:creator>
      <dc:date>2020-03-25T17:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634840#M188439</link>
      <description>&lt;P&gt;And if it's Windows, at a command prompt cd to the directory in question and:&lt;/P&gt;
&lt;P&gt;find /c /v "^$" *.csv &amp;gt;csvRowCount.txt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read csvRowCount.txt into SAS and don't forget to subtract 1 from the count.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634840#M188439</guid>
      <dc:creator>JerryV</dc:creator>
      <dc:date>2020-03-25T17:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634845#M188442</link>
      <description>Good solutions, I should have added this is for an automated process that will run weekly.</description>
      <pubDate>Wed, 25 Mar 2020 17:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634845#M188442</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2020-03-25T17:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634851#M188446</link>
      <description>Perhaps put the above OS commands, first, in the same script that launches the SAS session?</description>
      <pubDate>Wed, 25 Mar 2020 17:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634851#M188446</guid>
      <dc:creator>JerryV</dc:creator>
      <dc:date>2020-03-25T17:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634863#M188454</link>
      <description>&lt;P&gt;Even simpler: use a pipe.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data size_and_names;
infile "cd /path;wc -l *.csv" pipe truncover;
input size fname $200.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From that dataset, it is possible to get the counts and run the fdelete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 18:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634863#M188454</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-25T18:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634909#M188472</link>
      <description>&lt;P&gt;This method linked below had worked for me for csv file (as well as xlsx with slight modification), you can insert code to do a row count.&amp;nbsp; Seriously I wouldn't delete the the csv files in code, I would do it manually once I am satisfied the import worked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also a post by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; that looks pretty good&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/quot-Example-1-Import-All-CSV-Files-That-Exist-within-a/td-p/576286" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/quot-Example-1-Import-All-CSV-Files-That-Exist-within-a/td-p/576286&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 21:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/634909#M188472</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-03-25T21:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/635007#M188512</link>
      <description>&lt;P&gt;Firstly get all the pathname of these CSV file by DIR or LS command, and Run the following code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&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;data want;
infile cards truncover;
input path $ 100.;
n_obs=0;
infile dummy filevar=path end=last;
do while(not last);
 input;
 n_obs+1;
end;
file=path;
cards;
c:\temp\have.csv
c:\temp\x.csv
c:\temp\xx.csv
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 11:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/635007#M188512</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-26T11:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Recurse a Directory of CSV Files and get Row Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/635010#M188515</link>
      <description>&lt;P&gt;Thank you everyone for your responses!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 11:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recurse-a-Directory-of-CSV-Files-and-get-Row-Counts/m-p/635010#M188515</guid>
      <dc:creator>JeffreyLowe</dc:creator>
      <dc:date>2020-03-26T11:41:12Z</dc:date>
    </item>
  </channel>
</rss>

