BookmarkSubscribeRSS Feed
jmmedina252
Calcite | Level 5

My file is a .txt file with ',' delimiters and when using the below code:

 

proc import file="\\file_location\file_name.txt" dbms=dlm
   out=dlmread replace;
   delimiter=',';
   datarow=2;
   getnames=yes;
run;

 

I keep getting this error:

Unable to sample external file, no data in first 5 records.
ERROR: Import unsuccessful. See SAS Log for details.

2 REPLIES 2
Tom
Super User Tom
Super User

Since you told it that the first row has the variable names then it probably is only seeing one row in the file.

 

So you either do NOT have a file with lines of text at all.  Perhaps it is just a binary file or a file with fixed length records.

 

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.  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.

 

Try actually looking at the file to see what it contains.

 

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.

data _null_;
  infile "\\file_location\file_name.txt" recfm=f lrecl=100 obs=5 ;
  input;
  list;
run;

Also try reading it with different options for the TERMSTR= option of the infile statement.

data _null_;
  infile "\\file_location\file_name.txt" termstr=cr obs=5 ;
  input;
  list;
run;

Once you have looked at the file you can probably just skip the guessing procedure and write your own data step to read it.

Kurt_Bremser
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 626 views
  • 0 likes
  • 3 in conversation