DATA Step, Macro, Functions and more

Reading a space delimited file with names

Reply
Occasional Contributor
Posts: 5

Reading a space delimited file with names

Hi,

I have space delimited text file with spaces between two names. I want to use the infile option with delimiter as space and keep the name in the same column. Here is a snippet of the code I am having.

 

Agoura Hills  21127  290  290  0  3  5  48  64  155  15  0

and so on.

 

Thanks in advance.

Super User
Posts: 5,085

Re: Reading a space delimited file with names

There is one characteristic of the data that determines whether this is easy or difficult.  If you have two spaces after the name(s) instead of one, the problem is simple:

 

data want;

infile rawdata;

length place $ 20;

input place & var1 var2 var3 ....;

run;

 

Some short but relatively complex programming can handle the situation if there is only one space after the name(s).

Respected Advisor
Posts: 3,894

Re: Reading a space delimited file with names

@Sakthivel_Saran

Based on what you've posted the delimiter is a string of two consecutive blanks. If this is true then the following code should work:

data sample;
  infile datalines truncover dlmstr='  ' dsd;
  input @;
  input name :$20. numvar1-numvar11;
datalines;
Agoura Hills  21127  290  290  0  3  5  48  64  155  15  0
Agoura  21127  290  290  0  3  5  48  64  155  15  0
;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 3 in conversation