<?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 txt file error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864412#M341372</link>
    <description>&lt;P&gt;Since you told it that the first row has the variable names then it probably is only seeing one row in the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you either do NOT have a file with lines of text at all.&amp;nbsp; Perhaps it is just a binary file or a file with fixed length records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the most common cause is that the file was written by Excel on a Mac and it is using carriage return as the end of line marker.&amp;nbsp; For some reason Excel on the Mac didn't get the message that MacOS is a version of UNIX now and it should use linefeed as the end of line marker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try actually looking at the file to see what it contains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First try reading it as fixed length records and see if there are CR ('0D'x) or LF('0A'x) or both ('0D0A'x) at the end of the lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "\\file_location\file_name.txt" recfm=f lrecl=100 obs=5 ;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also try reading it with different options for the TERMSTR= option of the infile statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "\\file_location\file_name.txt" termstr=cr obs=5 ;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have looked at the file you can probably just skip the guessing procedure and write your own data step to read it.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2023 20:46:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-15T20:46:08Z</dc:date>
    <item>
      <title>Importing txt file error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864409#M341370</link>
      <description>&lt;P&gt;My file is a .txt file with ',' delimiters and when using the below code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import file="\\file_location\file_name.txt" dbms=dlm&lt;BR /&gt;&amp;nbsp; &amp;nbsp;out=dlmread replace;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;delimiter=',';&lt;BR /&gt;&amp;nbsp; &amp;nbsp;datarow=2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I keep getting this&amp;nbsp;error:&lt;/P&gt;&lt;P&gt;Unable to sample external file, no data in first 5 records.&lt;BR /&gt;ERROR: Import unsuccessful. See SAS Log for details.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 20:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864409#M341370</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-03-15T20:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Importing txt file error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864412#M341372</link>
      <description>&lt;P&gt;Since you told it that the first row has the variable names then it probably is only seeing one row in the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you either do NOT have a file with lines of text at all.&amp;nbsp; Perhaps it is just a binary file or a file with fixed length records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the most common cause is that the file was written by Excel on a Mac and it is using carriage return as the end of line marker.&amp;nbsp; For some reason Excel on the Mac didn't get the message that MacOS is a version of UNIX now and it should use linefeed as the end of line marker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try actually looking at the file to see what it contains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First try reading it as fixed length records and see if there are CR ('0D'x) or LF('0A'x) or both ('0D0A'x) at the end of the lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "\\file_location\file_name.txt" recfm=f lrecl=100 obs=5 ;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also try reading it with different options for the TERMSTR= option of the infile statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile "\\file_location\file_name.txt" termstr=cr obs=5 ;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have looked at the file you can probably just skip the guessing procedure and write your own data step to read it.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 20:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864412#M341372</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-15T20:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing txt file error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864414#M341374</link>
      <description>&lt;P&gt;Open the file with Notepad++ (a strongly recommended text editor for anyone doing programming). It will tell you the line-ending style (Windows, UNIX or Macintosh) in the status line.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 21:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-txt-file-error/m-p/864414#M341374</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-15T21:01:12Z</dc:date>
    </item>
  </channel>
</rss>

