BookmarkSubscribeRSS Feed
Sakthivel_Saran
Calcite | Level 5

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.

2 REPLIES 2
Astounding
PROC Star

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

Patrick
Opal | Level 21

@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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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