<?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: Merge Multiple csv files into one dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Multiple-csv-files-into-one-dataset/m-p/434946#M68928</link>
    <description>&lt;P&gt;If they're all in the same folder and the same layout you can use the approach outlined here that does everything you were trying to do:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or the INFILE statement has examples of keeping the file name used and/or reading from multiple files using the FILEVAR option and the FILENAME option to keep the name of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See Example 5:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0jglo3zfq5c0un10w8m07gpmanp" target="_blank"&gt;http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0jglo3zfq5c0un10w8m07gpmanp&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134773"&gt;@GijsTerBeek&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a) create a dataset of non consecutive .csv files in a certain folder&lt;/P&gt;
&lt;P&gt;b) loop through this dataset and load each file into a master dataset&lt;/P&gt;
&lt;P&gt;c) add one column to each row that contains the origin (filename) of that row&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step (a) works like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let servername=\\some\folder\;&lt;BR /&gt;libname out "&amp;amp;servername.Users\xxxx";&lt;BR /&gt;Filename filelist pipe "dir /b \\some\other\folder\*.txt"; &lt;BR /&gt;&lt;BR /&gt; Data out.filelist; &lt;BR /&gt; Infile filelist truncover;&lt;BR /&gt; Input filename $120.;&lt;BR /&gt; Run; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step (b) however keeps not using the variable for the filename:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out.completeset_total;
set out.filelist;
do i=1 to 3;
filepath="&amp;amp;servername"||filename;
call symput(fpath,TRIM(filepath));
call symput(fname,TRIM(filename));
put fpath;
filename abc3&amp;nbsp;"&amp;amp;servername.more\sub\folders\&amp;amp;fpath..txt";
infile abc3&amp;nbsp;truncover lrecl=1001 firstobs=2 ; input
@1 abc_RS BEST1.
@2 abc_anothercol BEST4.
&amp;amp;fpath.&amp;nbsp;
end;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Question:&amp;nbsp;&lt;/STRONG&gt;How can I make the filename statement loop through the variable fpath correctly?&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 16:23:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-02-07T16:23:04Z</dc:date>
    <item>
      <title>Merge Multiple csv files into one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Multiple-csv-files-into-one-dataset/m-p/434930#M68926</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to&amp;nbsp;&lt;/P&gt;&lt;P&gt;a) create a dataset of non consecutive .csv files in a certain folder&lt;/P&gt;&lt;P&gt;b) loop through this dataset and load each file into a master dataset&lt;/P&gt;&lt;P&gt;c) add one column to each row that contains the origin (filename) of that row&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step (a) works like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let servername=\\some\folder\;&lt;BR /&gt;libname out "&amp;amp;servername.Users\xxxx";&lt;BR /&gt;Filename filelist pipe "dir /b \\some\other\folder\*.txt"; &lt;BR /&gt;&lt;BR /&gt; Data out.filelist; &lt;BR /&gt; Infile filelist truncover;&lt;BR /&gt; Input filename $120.;&lt;BR /&gt; Run; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step (b) however keeps not using the variable for the filename:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data out.completeset_total;
set out.filelist;
do i=1 to 3;
filepath="&amp;amp;servername"||filename;
call symput(fpath,TRIM(filepath));
call symput(fname,TRIM(filename));
put fpath;
filename abc3&amp;nbsp;"&amp;amp;servername.more\sub\folders\&amp;amp;fpath..txt";
infile abc3&amp;nbsp;truncover lrecl=1001 firstobs=2 ; input
@1 abc_RS BEST1.
@2 abc_anothercol BEST4.
&amp;amp;fpath.&amp;nbsp;
end;
run;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Question:&amp;nbsp;&lt;/STRONG&gt;How can I make the filename statement loop through the variable fpath correctly?&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>Wed, 07 Feb 2018 16:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Multiple-csv-files-into-one-dataset/m-p/434930#M68926</guid>
      <dc:creator>GijsTerBeek</dc:creator>
      <dc:date>2018-02-07T16:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Multiple csv files into one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Merge-Multiple-csv-files-into-one-dataset/m-p/434946#M68928</link>
      <description>&lt;P&gt;If they're all in the same folder and the same layout you can use the approach outlined here that does everything you were trying to do:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or the INFILE statement has examples of keeping the file name used and/or reading from multiple files using the FILEVAR option and the FILENAME option to keep the name of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See Example 5:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0jglo3zfq5c0un10w8m07gpmanp" target="_blank"&gt;http://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0jglo3zfq5c0un10w8m07gpmanp&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134773"&gt;@GijsTerBeek&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a) create a dataset of non consecutive .csv files in a certain folder&lt;/P&gt;
&lt;P&gt;b) loop through this dataset and load each file into a master dataset&lt;/P&gt;
&lt;P&gt;c) add one column to each row that contains the origin (filename) of that row&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step (a) works like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let servername=\\some\folder\;&lt;BR /&gt;libname out "&amp;amp;servername.Users\xxxx";&lt;BR /&gt;Filename filelist pipe "dir /b \\some\other\folder\*.txt"; &lt;BR /&gt;&lt;BR /&gt; Data out.filelist; &lt;BR /&gt; Infile filelist truncover;&lt;BR /&gt; Input filename $120.;&lt;BR /&gt; Run; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step (b) however keeps not using the variable for the filename:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out.completeset_total;
set out.filelist;
do i=1 to 3;
filepath="&amp;amp;servername"||filename;
call symput(fpath,TRIM(filepath));
call symput(fname,TRIM(filename));
put fpath;
filename abc3&amp;nbsp;"&amp;amp;servername.more\sub\folders\&amp;amp;fpath..txt";
infile abc3&amp;nbsp;truncover lrecl=1001 firstobs=2 ; input
@1 abc_RS BEST1.
@2 abc_anothercol BEST4.
&amp;amp;fpath.&amp;nbsp;
end;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Question:&amp;nbsp;&lt;/STRONG&gt;How can I make the filename statement loop through the variable fpath correctly?&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 16:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Merge-Multiple-csv-files-into-one-dataset/m-p/434946#M68928</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-07T16:23:04Z</dc:date>
    </item>
  </channel>
</rss>

