DATA Step, Macro, Functions and more

multiple delimiter reading scan function??

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 112
Accepted Solution

multiple delimiter reading scan function??

SAS group, 

 

         could you please help me get this from string name (3 spaces as delimiters, between name and city). I want to extract name. 

Any thoughts please. I have sas eg and it is not taking scan function (quotation marks has 3 spaces in between). It worked in SAS 9.3, but not in sas eg. 

example: name1=scan(name,1,"   ");

 have file 

name   city   state  zipcode

wal mart   siouxcity   ia  14525

arthur chiropracter nd   richmond   ca  25684

want file

wal mart

arthur chiropracter nd

 

Thanks in advance.

 


Accepted Solutions
Solution
‎09-25-2017 01:27 PM
Super User
Posts: 6,933

Re: multiple delimiter reading scan function??

This is mildly clumsy, but it should work when you are searching for the beginning of the incoming string:

 

name1 = substr(name, 1, index(name, '   ') ) ;

 

View solution in original post


All Replies
Super User
Posts: 13,941

Re: multiple delimiter reading scan function??

Are you reading an external file? If you actually have 3 characters between each field you could use the dlmstr='   ' option instead of dlm

 

However the data you show has only two spaces between the state and the zipcode so perhaps dlmstr='  ' (two spaces) will actually work to read the file.

 

Solution
‎09-25-2017 01:27 PM
Super User
Posts: 6,933

Re: multiple delimiter reading scan function??

This is mildly clumsy, but it should work when you are searching for the beginning of the incoming string:

 

name1 = substr(name, 1, index(name, '   ') ) ;

 

Frequent Contributor
Posts: 112

Re: multiple delimiter reading scan function??

This works thanks Astounding
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 936 views
  • 1 like
  • 3 in conversation