<?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: write a macro to import data from multiple files with sequentially incremental names into one fi in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265746#M52301</link>
    <description>&lt;P&gt;Do all of the files&amp;nbsp;have the same structure?&lt;/P&gt;
&lt;P&gt;Is there a header row in each file?&lt;/P&gt;
&lt;P&gt;Do you have a program that will read one of the files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are the same structure you likly do not need a macro. And if you were planning on using Proc Import were very likely to cause all kinds of issues with character variables being of different lengths in different sets and some variables may be numeric in one and character in another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you provide an example TXT file we can likely give you a good start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can assign a fileref that identifies multiple files to SAS such as&lt;/P&gt;
&lt;P&gt;Filename myfiles "c:\path\April_*.txt";&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 19:14:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-04-22T19:14:45Z</dc:date>
    <item>
      <title>write a macro to import data from multiple files with sequentially incremental names into one file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265743#M52300</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 1000 txt files with sequencially increasing naming convention&amp;nbsp;in a shared location.&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;P&gt;april_1&lt;/P&gt;&lt;P&gt;april_2&lt;/P&gt;&lt;P&gt;april_3&lt;/P&gt;&lt;P&gt;april_4&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;april_1000&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to be load all of them using&amp;nbsp;SAS Macro&amp;nbsp;to create one large file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Ankita&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265743#M52300</guid>
      <dc:creator>Ankita</dc:creator>
      <dc:date>2016-04-22T19:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265746#M52301</link>
      <description>&lt;P&gt;Do all of the files&amp;nbsp;have the same structure?&lt;/P&gt;
&lt;P&gt;Is there a header row in each file?&lt;/P&gt;
&lt;P&gt;Do you have a program that will read one of the files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are the same structure you likly do not need a macro. And if you were planning on using Proc Import were very likely to cause all kinds of issues with character variables being of different lengths in different sets and some variables may be numeric in one and character in another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you provide an example TXT file we can likely give you a good start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can assign a fileref that identifies multiple files to SAS such as&lt;/P&gt;
&lt;P&gt;Filename myfiles "c:\path\April_*.txt";&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265746#M52301</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-22T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265748#M52302</link>
      <description>&lt;P&gt;You don't need macro for this.&amp;nbsp; You can create a fileref which uses a wild card, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename april "d:\junk\april_*.txt";

data _null_;
  infile april;
  input ;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will read all files that start with april.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265748#M52302</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-04-22T19:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265758#M52307</link>
      <description>&lt;P&gt;Q1. Do all of the files&amp;nbsp;have the same structure?&lt;/P&gt;&lt;P&gt;A1. Yes all the files have same structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Q2.&amp;nbsp;&lt;/SPAN&gt;Is there a header row in each file?&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A2. Yes there is header in each file&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Q3.&lt;/SPAN&gt;Do you have a program that will read one of the files?&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A3. No I dont have the program.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ankita&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 19:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265758#M52307</guid>
      <dc:creator>Ankita</dc:creator>
      <dc:date>2016-04-22T19:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265765#M52313</link>
      <description>&lt;P&gt;If the file is delimited in some way such as a comma or space between each variable (colum) then you could run Proc Import on ONE file. The procedure will generate data step code that you can save and modify as needed. If the data is FIXED column then you will have to look up how to read column input (not difficult, just tedious). After you have a program that will read ONE file then you make some modifications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the infile statement to reference either a filereference created with a Filname statement or replace the single file name with the example strings we have shown using a wild card like: Infile "c:\path\April_*.txt"; &amp;nbsp;add the option EOV=skip (This is used to skip over reading the header rows , Firstobs = 2 (to skip reading the header row of the first file)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Before&lt;/STRONG&gt; you current input statement add these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input @;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* this looks at the current input line and waits*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if skip then skip=0;&amp;nbsp; /* The EOV option above sets a temporary variable (SKIP) to a value of 1 when it is the first record of a new file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in the list, reset the value to 0. The Else means that a first line (header row) won't be read*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Else do;&lt;/P&gt;
&lt;P&gt;&amp;lt;here you put it your&amp;nbsp;working program's INPUT statement and any other code you may have&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; End;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 20:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265765#M52313</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-22T20:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265793#M52325</link>
      <description>&lt;P&gt;Solve #3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use proc import on one file. Then check your log, it will have the input code you need. You may need to modify it so that it correctly reads in your data. Make sure you have this step working.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then follow the steps here:&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;</description>
      <pubDate>Sat, 23 Apr 2016 00:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265793#M52325</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-23T00:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265823#M52336</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for your responses.&amp;nbsp; I have used the option EOV=skip but still find the headers. Is there any advance method to resolve it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ankita&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2016 14:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265823#M52336</guid>
      <dc:creator>Ankita</dc:creator>
      <dc:date>2016-04-23T14:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265828#M52340</link>
      <description>&lt;P&gt;There is no EOV=skip option as far as I'm aware.&lt;/P&gt;
&lt;P&gt;EOV creates a variable with an indicator if the record is the first in a file. Please read the documentation around this variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you check the code in the link I provided, it shows how to work around headers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you set EOV to the variable EOV.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "Path\*.txt" eov=eov filename=filename truncover;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&amp;nbsp;you don't use the INPUT statement. You'll notice the INPUT is the ELSE for an IF/ELSE condition.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;*Check if this is the first record or the first record in a new file;
*If it is, replace the filename with the new file name and move to next line;
if _n_ eq 1 or eov then do;
txt_file_name = scan(filename, -1, "\");
eov=0;
end;&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2016 15:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265828#M52340</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-23T15:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265884#M52355</link>
      <description>&lt;P&gt;Thanks for suggesting me the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written my code accordingly&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Import_all;&lt;BR /&gt;Infile "R:\sas\opt\april_2016_*.txt" EOV=skip;&lt;BR /&gt;input @;&amp;nbsp;&lt;BR /&gt;if skip then skip=0;&lt;BR /&gt;Else do;&lt;BR /&gt;input Name$ Number Price;&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the output the header is getting eliminated from 2nd file onwards however there is a blank&amp;nbsp;observation instead.&lt;/P&gt;&lt;P&gt;Also for the first file partially header is getting displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please please help as where exactly I am going wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I have attached the output screen shot below. Obs 1 shows the name which is ideally the variable name.&lt;/P&gt;&lt;P&gt;14 and 27 is blank as they had headers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ankita&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12483iF2D508C294C1CE56/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="output.png" title="output.png" /&gt;</description>
      <pubDate>Sun, 24 Apr 2016 11:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265884#M52355</guid>
      <dc:creator>Ankita</dc:creator>
      <dc:date>2016-04-24T11:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: write a macro to import data from multiple files with sequentially incremental names into one fi</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265900#M52361</link>
      <description>&lt;P&gt;I'll post more later but here's a quick idea.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look ok at the link provided above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace ONLY the infile and input statements. The rest of the code will be the same.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2016 16:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-a-macro-to-import-data-from-multiple-files-with/m-p/265900#M52361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-24T16:06:07Z</dc:date>
    </item>
  </channel>
</rss>

