<?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 Importing multiple CSVs from multiple folders in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601407#M173949</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import multiple csvs, from multiple folders, where the folder name increments by 1 each day. Is there a way I can import multiple CSVs where the folder each day increments by 1?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Day1 = C:temp\00001&lt;/P&gt;&lt;P&gt;Day = C:temp\00002&lt;/P&gt;&lt;P&gt;end ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a macro that will import multiple CSVs from the same directory but I can't figure out how to import from multiple directories&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code below to pull all CSV from same dir....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro drive(dir,ext);&lt;BR /&gt;%local cnt filrf rc did memcnt name;&lt;BR /&gt;%let cnt=0;&lt;BR /&gt;%let filrf=mydir;&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did ne 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let memcnt=%sysfunc(dnum(&amp;amp;did));&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;memcnt;&lt;BR /&gt;%let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);&lt;/P&gt;&lt;P&gt;%if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then&lt;BR /&gt;%do;&lt;BR /&gt;%if %superq(ext) = %superq(name) %then&lt;BR /&gt;%do;&lt;BR /&gt;%let cnt=%eval(&amp;amp;cnt+1);&lt;BR /&gt;%put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt&lt;BR /&gt;dbms=csv replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %put &amp;amp;dir cannot be open.;&lt;BR /&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;%mend drive;&lt;BR /&gt;&lt;BR /&gt;%drive(C:Temp\_20191101-000031,csv)&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;code below to try and add pull from multiple dir at same time....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i = 30 %to 31;&lt;BR /&gt;%drive("C:temp\-0000&amp;amp;i,csv");&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test&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, 04 Nov 2019 16:52:42 GMT</pubDate>
    <dc:creator>zdeb15</dc:creator>
    <dc:date>2019-11-04T16:52:42Z</dc:date>
    <item>
      <title>Importing multiple CSVs from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601407#M173949</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import multiple csvs, from multiple folders, where the folder name increments by 1 each day. Is there a way I can import multiple CSVs where the folder each day increments by 1?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Day1 = C:temp\00001&lt;/P&gt;&lt;P&gt;Day = C:temp\00002&lt;/P&gt;&lt;P&gt;end ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a macro that will import multiple CSVs from the same directory but I can't figure out how to import from multiple directories&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code below to pull all CSV from same dir....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro drive(dir,ext);&lt;BR /&gt;%local cnt filrf rc did memcnt name;&lt;BR /&gt;%let cnt=0;&lt;BR /&gt;%let filrf=mydir;&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did ne 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let memcnt=%sysfunc(dnum(&amp;amp;did));&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;memcnt;&lt;BR /&gt;%let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);&lt;/P&gt;&lt;P&gt;%if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then&lt;BR /&gt;%do;&lt;BR /&gt;%if %superq(ext) = %superq(name) %then&lt;BR /&gt;%do;&lt;BR /&gt;%let cnt=%eval(&amp;amp;cnt+1);&lt;BR /&gt;%put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt&lt;BR /&gt;dbms=csv replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %put &amp;amp;dir cannot be open.;&lt;BR /&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;%mend drive;&lt;BR /&gt;&lt;BR /&gt;%drive(C:Temp\_20191101-000031,csv)&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;code below to try and add pull from multiple dir at same time....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i = 30 %to 31;&lt;BR /&gt;%drive("C:temp\-0000&amp;amp;i,csv");&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test&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, 04 Nov 2019 16:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601407#M173949</guid>
      <dc:creator>zdeb15</dc:creator>
      <dc:date>2019-11-04T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSVs from multiple folders [how to improve your question]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601417#M173954</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272807"&gt;@zdeb15&lt;/a&gt;,&lt;/P&gt;&lt;BR /&gt; &lt;P&gt;Your question requires more details before experts can help.&amp;nbsp;Can you revise your question to include more information?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Review this checklist:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Specify a meaningful subject line for your topic.&amp;nbsp; Avoid generic subjects like "need help," "SAS query," or "urgent."&lt;/LI&gt;
&lt;LI&gt;When appropriate, provide sample data in text or DATA step format.&amp;nbsp; See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;this article for one method&lt;/A&gt;&amp;nbsp;you can use.&lt;/LI&gt;
&lt;LI&gt;If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition.&amp;nbsp;Use the&amp;nbsp;&lt;STRONG&gt;Photos&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;button to include the image in your message.&lt;BR /&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 279px;"&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/16608i91A52F817EAC9A69/image-dimensions/279x150?v=1.0" width="279" height="150" alt="use_buttons.png" title="use_buttons.png" /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;It also helps to include an example (table or picture) of the result that you're trying to achieve.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To edit your original message, select the "blue gear" icon at the top of the message and select&amp;nbsp;&lt;STRONG&gt;Edit Message&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;From there you can adjust the title and add more details to the body of the message.&amp;nbsp; Or, simply reply to this message with any additional information you can supply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" style="width: 229px;"&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/16605iAC020BC79315B045/image-size/large?v=1.0&amp;amp;px=600" alt="edit_post.png" title="edit_post.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;SAS experts are eager to help -- help&amp;nbsp;&lt;EM&gt;them&lt;/EM&gt; by providing as much detail as you can.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style:italic;font-size:smaller;"&gt;This prewritten response was triggered for you by fellow SAS Support Communities member &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;.</description>
      <pubDate>Mon, 04 Nov 2019 15:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601417#M173954</guid>
      <dc:creator>Community_Guide</dc:creator>
      <dc:date>2019-11-04T15:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple CSVs from multiple folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601646#M174053</link>
      <description>&lt;P&gt;Use OS command ( LS or DIR ) to get these CSV pathname . And;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input fname $80.;&lt;/P&gt;
&lt;P&gt;infile dummy filevar=fname end=last truncover dsd ;&lt;/P&gt;
&lt;P&gt;do while(not last);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; input x1 x2 x3 x4 .....;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;C:temp\00001\x.csv&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;C:temp\00002\x.csv&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;..............&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 12:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-CSVs-from-multiple-folders/m-p/601646#M174053</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-05T12:48:20Z</dc:date>
    </item>
  </channel>
</rss>

