<?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 multiple .dat files in one step in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789835#M32437</link>
    <description>&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;If the names are similar (and unique) just use a wildcard in the filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfiles*.dat' ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Define a fileref that points to both files and use the fileref in the INFILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydata ('file1.dat','file2.dat') ;
...
infile mydata ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or create a dataset with the list of files and use the FILEVAR= option on the INFILE statement.&amp;nbsp; So if you have a dataset name FILELIST with a variable named FILENAME then use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set filelist ;
  infile dummy filevar=filename&amp;nbsp;end=eof;
&amp;nbsp;&amp;nbsp;do&amp;nbsp;while&amp;nbsp;(not&amp;nbsp;eof);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;input&amp;nbsp;....&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;
&amp;nbsp;&amp;nbsp;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Jan 2022 22:08:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-12T22:08:58Z</dc:date>
    <item>
      <title>import multiple .dat files in one step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789832#M32436</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two separate .dat files.&amp;nbsp;I need to import files by using DATA and INFILE statements.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both files have same variables different values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way for me to import two files so I can use same length, format options (reduce program size).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 21:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789832#M32436</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-01-12T21:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: import multiple .dat files in one step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789835#M32437</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;If the names are similar (and unique) just use a wildcard in the filename.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfiles*.dat' ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Define a fileref that points to both files and use the fileref in the INFILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mydata ('file1.dat','file2.dat') ;
...
infile mydata ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or create a dataset with the list of files and use the FILEVAR= option on the INFILE statement.&amp;nbsp; So if you have a dataset name FILELIST with a variable named FILENAME then use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set filelist ;
  infile dummy filevar=filename&amp;nbsp;end=eof;
&amp;nbsp;&amp;nbsp;do&amp;nbsp;while&amp;nbsp;(not&amp;nbsp;eof);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;input&amp;nbsp;....&amp;nbsp;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;
&amp;nbsp;&amp;nbsp;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789835#M32437</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-12T22:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: import multiple .dat files in one step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789836#M32438</link>
      <description>&lt;P&gt;For sure!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However there are some things to consider:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Headers in each file?&lt;/LI&gt;
&lt;LI&gt;How do you know which record a file comes from - do you need this information?&lt;/LI&gt;
&lt;LI&gt;Do you need separate files for each file or a single file?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Rough outline is 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" rel="noopener"&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;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324991"&gt;@dht115&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two separate .dat files.&amp;nbsp;I need to import files by using DATA and INFILE statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both files have same variables different values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way for me to import two files so I can use same length, format options (reduce program size).&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, 12 Jan 2022 22:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789836#M32438</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-12T22:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: import multiple .dat files in one step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789838#M32439</link>
      <description>&lt;P&gt;I have two separate .dat files and need to create two separate dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;both .dat files have different name&amp;nbsp;&lt;/P&gt;&lt;P&gt;both dataset needs to have different name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789838#M32439</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-01-12T22:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: import multiple .dat files in one step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789842#M32440</link>
      <description>&lt;P&gt;Then wrap the code into a macro? You can write a data step that handles this but a macro would be easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Replace the inner code with working code for one data set and then it generalizes. Honestly, for just two files I'd probably copy and paste (rough guideline is if you repeat it 3 times or more, then generalize).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_dat_file(path=, out=);

data &amp;amp;out;
infile "&amp;amp;path" dsd truncover;
input ........;


run;


%mend;

%import_dat_file(path=/pathtofile1/myfile1.dat, out=data1);
%import_dat_file(path=/pathtofile1/myfile2.dat, out=data1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/import-multiple-dat-files-in-one-step/m-p/789842#M32440</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-12T22:20:27Z</dc:date>
    </item>
  </channel>
</rss>

