<?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: importing mulitple files and adding filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/importing-mulitple-files-and-adding-filename/m-p/539440#M148624</link>
    <description>You can't with PROC IMPORT, but you can if you use a data step. You can copy the code from the log and add the FILENAME/FILEVAR options to the INFILE statement. &lt;BR /&gt;</description>
    <pubDate>Thu, 28 Feb 2019 18:44:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-28T18:44:29Z</dc:date>
    <item>
      <title>importing mulitple files and adding filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-mulitple-files-and-adding-filename/m-p/539419#M148620</link>
      <description>&lt;P&gt;I am attempting to import multiple text files.&amp;nbsp; I would like to add the file name as a column in the output file.&amp;nbsp; Is there an easy way to add this additional detail.&amp;nbsp;My current code is written below&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;filename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; fref &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;pipe&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"ls /unixlocation/files_&amp;amp;Mth.*.txt"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.file_curr;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; fref;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;file&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = scan(_infile_,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'/'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;import&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datafile&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"/unixlocation/files_&amp;amp;Mth.*.txt"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=output(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;rename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=(VAR1=newname1 VAR2=newname2 VAR6=newname3 VAR9=newname4))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;dbms&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=csv&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;replace&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;delimiter&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;GETNAMES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=NO;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datarow&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;guessingrows&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;32000&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 18:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-mulitple-files-and-adding-filename/m-p/539419#M148620</guid>
      <dc:creator>thomask23</dc:creator>
      <dc:date>2019-02-28T18:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: importing mulitple files and adding filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-mulitple-files-and-adding-filename/m-p/539440#M148624</link>
      <description>You can't with PROC IMPORT, but you can if you use a data step. You can copy the code from the log and add the FILENAME/FILEVAR options to the INFILE statement. &lt;BR /&gt;</description>
      <pubDate>Thu, 28 Feb 2019 18:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-mulitple-files-and-adding-filename/m-p/539440#M148624</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-28T18:44:29Z</dc:date>
    </item>
  </channel>
</rss>

