<?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: Read and append files in different folders in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257482#M49443</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34942"&gt;@xiaobing﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;has outlined:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename all ('C:\Test\abc.txt', 'C:\Temp\Data\abc.txt');

data want;
length path $260; /* adapt the length if necessary */
infile all filename=path; /* add options as needed */
input x y z; /* adapt as appropriate */
folder=substr(path,1,max(find(path,'\',-999)-1,3));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that the two raw data files (abc.txt) not only have the same name, but also the same structure. Also, it creates a new &lt;EM&gt;variable&lt;/EM&gt; (named FOLDER), not an &lt;EM&gt;observation&lt;/EM&gt;, which indicates the source folder of each observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Mar 2016 23:49:48 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-03-17T23:49:48Z</dc:date>
    <item>
      <title>Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257434#M49426</link>
      <description>&lt;P&gt;Hello, I'm a beginner on SAS and I have a question of writing a macro. Basically I want to write a macro to read several files with the same name in different folders. For example, folder a and b both have a file name x. What I want to do is to read append the two files and create another observation which indicates which folder the part of new combined file comes from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XB&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 19:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257434#M49426</guid>
      <dc:creator>xiaobing</dc:creator>
      <dc:date>2016-03-17T19:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257443#M49430</link>
      <description>&lt;P&gt;Since you're a beginner in SAS, there are a couple of requirements before you even think about writing a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, write an example of the program.&amp;nbsp; Hard-code everything, and make sure that the program works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, consider what will happen when turning the program into a macro.&amp;nbsp; Which parts of the program will never change, and which parts will change each time you call the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only then can you even consider writing a macro to accomplish the task.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 20:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257443#M49430</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-17T20:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257446#M49433</link>
      <description>&lt;P&gt;In addition to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;'s good advice the content of the files makes a little difference.&lt;/P&gt;
&lt;P&gt;It may well be possible to read all of the files using a single file reference such as :&lt;/P&gt;
&lt;P&gt;Filename MyInput ("C:\path\folder1\myfile.text" "C:\path\folder2\myfile.text" "C:\path\folder3\myfile.text");&lt;/P&gt;
&lt;P&gt;and use that type reference in the INFILE statement along with the the FILENAME option to capture the name of the specific file.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 20:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257446#M49433</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-17T20:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257482#M49443</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34942"&gt;@xiaobing﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;has outlined:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename all ('C:\Test\abc.txt', 'C:\Temp\Data\abc.txt');

data want;
length path $260; /* adapt the length if necessary */
infile all filename=path; /* add options as needed */
input x y z; /* adapt as appropriate */
folder=substr(path,1,max(find(path,'\',-999)-1,3));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that the two raw data files (abc.txt) not only have the same name, but also the same structure. Also, it creates a new &lt;EM&gt;variable&lt;/EM&gt; (named FOLDER), not an &lt;EM&gt;observation&lt;/EM&gt;, which indicates the source folder of each observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2016 23:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257482#M49443</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-17T23:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257796#M49544</link>
      <description>&lt;P&gt;Are these files SAS datasets or text files? Is this related to your latest question?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 01:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257796#M49544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-20T01:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Read and append files in different folders</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257797#M49545</link>
      <description>&lt;P&gt;Hello, Reeza.Thanks for the reply.&lt;/P&gt;
&lt;P&gt;It's SAS dataset. So Basically, I have 10 folders with different names. Within each folder, there were many sas datasets. What I basically need is to create a new variable that's equal to its belonging folder name for each dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XiaoBing&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 01:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-and-append-files-in-different-folders/m-p/257797#M49545</guid>
      <dc:creator>xiaobing</dc:creator>
      <dc:date>2016-03-20T01:14:21Z</dc:date>
    </item>
  </channel>
</rss>

