<?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: Import and Append all CSV files in folder - SAS EG in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273712#M269549</link>
    <description>&lt;P&gt;Appending makes me believe all of the files are of the same structure (which is likely not be the case if you were planning on using Proc import).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a recent thread on reading identical files. These were tab separated but the only change would be to change the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-import-and-merge-all-TSV-files-in-a-folder/m-p/273039#M18938" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-import-and-merge-all-TSV-files-in-a-folder/m-p/273039#M18938&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OP hasn't marked whether it was his solution but the last post is what I would suggest if thes are all the same, OR if you have common names with structures then to read each batch. The resulting data will be in order of the dataset names per your OS sort order which may not match your intent such as if month Names are used instead of month numbers in the file: XXXJAN will come after XXXAPR.&lt;/P&gt;</description>
    <pubDate>Fri, 27 May 2016 20:09:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-27T20:09:49Z</dc:date>
    <item>
      <title>Import and Append all CSV files in folder - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273700#M269547</link>
      <description>&lt;P&gt;I'm trying to use code to genetrate a list of the csv files in a folder and then run a macro to import and append these files. I've checked other posts similar to this and have gotten close but the import and append code&amp;nbsp;doesn't run successfully (the filelist is created successfully.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data filelist;&lt;BR /&gt;keep filename;&lt;BR /&gt;length fref $8 filename $80;&lt;BR /&gt;rc = filename(fref, "/read_in_checks");&amp;nbsp;&lt;BR /&gt;if rc = 0 then&lt;BR /&gt;do;&lt;BR /&gt;did = dopen(fref);&lt;BR /&gt;rc = filename(fref);&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;BR /&gt;length msg $200.;&lt;BR /&gt;msg = sysmsg();&lt;BR /&gt;put msg=;&lt;BR /&gt;did = .;&lt;BR /&gt;end;&lt;BR /&gt;if did &amp;lt;= 0&lt;BR /&gt;then&lt;BR /&gt;putlog 'ERR' 'OR: Unable to open directory.';&lt;BR /&gt;dnum = dnum(did);&lt;BR /&gt;do i = 1 to dnum;&lt;BR /&gt;filename = dread(did, i);&lt;BR /&gt;/* If this entry is a file, then output. */&lt;BR /&gt;fid = mopen(did, filename);&lt;BR /&gt;if fid &amp;gt; 0&lt;BR /&gt;then&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc = dclose(did);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*list of csv file names is created above and used in macro below, the fiilelist is correct, just cant get the macro below to work.*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro callmacro;&lt;/P&gt;&lt;P&gt;data _null_;set filelist nobs=nobs;&lt;BR /&gt;call symput('TotFiles',put(nobs,8.));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%do a=1 %to &amp;amp;&amp;amp;TotFiles;&lt;/P&gt;&lt;P&gt;data _null_;set filelist;&lt;BR /&gt;if _n_=&amp;amp;&amp;amp;a;&lt;BR /&gt;call symputx('csvdatafilex',put(filename,$32.));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%loops(&amp;amp;&amp;amp;csvdatafilex);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;BR /&gt;%callmacro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log Results:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;23 GOPTIONS ACCESSIBLE;&lt;BR /&gt;24 /* Insert custom code before submitted code here */&lt;BR /&gt;25 options dtreset validvarname=v7;&lt;BR /&gt;26&lt;BR /&gt;27&lt;BR /&gt;28 options mprint;&lt;BR /&gt;29 %macro callmacro;&lt;BR /&gt;30&lt;BR /&gt;31 data _null_;set filelist nobs=nobs;&lt;BR /&gt;32 call symput('TotFiles',put(nobs,8.));&lt;BR /&gt;33 run;&lt;BR /&gt;34&lt;BR /&gt;35 %do a=1 %to &amp;amp;&amp;amp;TotFiles;&lt;BR /&gt;36&lt;BR /&gt;37 data _null_;set filelist;&lt;BR /&gt;38 if _n_=&amp;amp;&amp;amp;a;&lt;BR /&gt;39 call symputx('csvdatafilex',put(filename,$32.));&lt;BR /&gt;40 run;&lt;BR /&gt;41&lt;BR /&gt;42 %loops(&amp;amp;&amp;amp;csvdatafilex);&lt;BR /&gt;43&lt;BR /&gt;44 %end;&lt;BR /&gt;45&lt;BR /&gt;46 %mend;&lt;BR /&gt;47 %callmacro&lt;BR /&gt;MPRINT(CALLMACRO): data _null_;&lt;BR /&gt;MPRINT(CALLMACRO): set filelist nobs=nobs;&lt;BR /&gt;MPRINT(CALLMACRO): call symput('TotFiles',put(nobs,8.));&lt;BR /&gt;MPRINT(CALLMACRO): run;&lt;/P&gt;&lt;P&gt;NOTE: There were 193 observations read from the data set WORK.FILELIST.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;2 The SAS System 14:41 Friday, May 27, 2016&lt;/P&gt;&lt;P&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;MPRINT(CALLMACRO): data _null_;&lt;BR /&gt;MPRINT(CALLMACRO): set filelist;&lt;BR /&gt;MPRINT(CALLMACRO): if _n_=1;&lt;BR /&gt;MPRINT(CALLMACRO): call symputx('csvdatafilex',put(filename,$32.));&lt;BR /&gt;MPRINT(CALLMACRO): run;&lt;/P&gt;&lt;P&gt;NOTE: There were 193 observations read from the data set WORK.FILELIST.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;NOTE: Line generated by the invoked macro "CALLMACRO".&lt;BR /&gt;47 data _null_;set filelist; if _n_=&amp;amp;&amp;amp;a; call symputx('csvdatafilex',put(filename,$32.)); run; %loops(&amp;amp;&amp;amp;csvdatafilex);&lt;BR /&gt;_&lt;BR /&gt;180&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;WARNING: Apparent invocation of macro LOOPS not resolved.&lt;BR /&gt;MPRINT(CALLMACRO): %loops(ACSIS_HSHLD_HIST_CLM_B_checks.cs);&lt;/P&gt;&lt;P&gt;MPRINT(CALLMACRO): data _null_;&lt;BR /&gt;MPRINT(CALLMACRO): set filelist;&lt;BR /&gt;MPRINT(CALLMACRO): if _n_=2;&lt;BR /&gt;MPRINT(CALLMACRO): call symputx('csvdatafilex',put(filename,$32.));&lt;BR /&gt;MPRINT(CALLMACRO): run;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 19:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273700#M269547</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-05-27T19:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Import and Append all CSV files in folder - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273707#M269548</link>
      <description>&lt;P&gt;You don't need a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the documentation and the filevar option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/techsup/technote/ts581.pdf" target="_blank"&gt;https://support.sas.com/techsup/technote/ts581.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or Example 5 in 9.2 docs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code as is doesn't include an import step, the macro loops isn't defined for us.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro variables are probably not resolving properly, you can use options MPRINT and SYMBOLGEN to see them as they loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;&amp;amp; should be only one &amp;amp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be to use Call execute instead of the loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 20:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273707#M269548</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-27T20:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Import and Append all CSV files in folder - SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273712#M269549</link>
      <description>&lt;P&gt;Appending makes me believe all of the files are of the same structure (which is likely not be the case if you were planning on using Proc import).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a recent thread on reading identical files. These were tab separated but the only change would be to change the delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-import-and-merge-all-TSV-files-in-a-folder/m-p/273039#M18938" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-import-and-merge-all-TSV-files-in-a-folder/m-p/273039#M18938&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OP hasn't marked whether it was his solution but the last post is what I would suggest if thes are all the same, OR if you have common names with structures then to read each batch. The resulting data will be in order of the dataset names per your OS sort order which may not match your intent such as if month Names are used instead of month numbers in the file: XXXJAN will come after XXXAPR.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 20:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-and-Append-all-CSV-files-in-folder-SAS-EG/m-p/273712#M269549</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-27T20:09:49Z</dc:date>
    </item>
  </channel>
</rss>

