BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Hello,

I have a text file like that:  PB.PXDWXBX.SEDWVPAB.MP0|2918951|255186908|

 

Here's the code:

 

%let path1=/****/control/  ;

proc import datafile = "&path1./control/be_MAR2025_premcntrlfile.txt'
 out = classic_control_file
 dbms = dlm
 replace
 ;
 delimiter = '|';
run;

I have tried the above sas code and I am getting the error: Unable to sample external file, no data in first 5 records. ERROR: Import unsuccessful. See SAS Log for details

 

How to solve that issue

3 REPLIES 3
data_null__
Jade | Level 19

You probably just need GETNAMES=NO;

 

filename FT15F001 temp;
parmcards;
PB.PXDWXBX.SEDWVPAB.MP0|2918951|255186908|
;;;;

proc import datafile=Ft15F001 out=test dbms=csv;
   getnames=no;
   delimiter='|';
   run;

proc print;
   run;

Capture.PNG

ballardw
Super User

Is this "one line" file supposed to have more than one observation?

I ask because there are some files that do not use end of line or carriage controls as record delimiters and Proc Import is likely not to be the tool to read such.

Tom
Super User Tom
Super User

You rarely need (or want) to use PROC IMPORT to read a delimited text file.  And for a file like that it goes triple.

 

Just READ the file.

You could read it into multiple observations if you are not sure how many values are on the line.

First lets convert your example into a FILE so we have something to program against.

filename have temp;
options parmcards=have;
parmcards;
PB.PXDWXBX.SEDWVPAB.MP0|2918951|255186908|
;;;;

Now just run a normal SAS data step to read in the file.

data want;
  infile have dsd dlm='|';
  var+1;
  input value :$20. @@;
run;

Results

Obs    var    value

 1      1     PB.PXDWXBX.SEDWVPAB.
 2      2     2918951
 3      3     255186908
 4      4

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 323 views
  • 2 likes
  • 4 in conversation