Help using Base SAS procedures

Choosing output based on certain Text String

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Choosing output based on certain Text String

Hello,

 

I have a dataset with a bunch of addresses, unfortunately they are all combined into one line and I need to parse out everything that comes after the person's name into one line.

 

Data that I have:

 

id         Name               address_line                                              city_state         zipcode

1          John Doe          john doe 123 Central Avenue                 New York, NY    12345

 

Data I want:

id         Name               address_line_1                                          city_state         zipcode

1          John Doe         123 Central Avenue                                 New York, NY    12345

 

 

I know I probably have to use index and substring or some combination of those, but I really have no idea where to start.


Accepted Solutions
Solution
‎05-31-2016 11:07 AM
Super User
Posts: 5,498

Re: Choosing output based on certain Text String

Posted in reply to jacob_klimek

That looks like the right set of tools, but I think you are looking for this:

 

address_line_1 = substr(address_line, length(name) + 2);

View solution in original post


All Replies
Super User
Posts: 19,770

Re: Choosing output based on certain Text String

Posted in reply to jacob_klimek

Use the length of name as the second argument to substr function. It tells it where to start the substr and leaving out the third parameter tells it to take the rest of the string. 

 

Address = substr(address_line1, length(name));
Solution
‎05-31-2016 11:07 AM
Super User
Posts: 5,498

Re: Choosing output based on certain Text String

Posted in reply to jacob_klimek

That looks like the right set of tools, but I think you are looking for this:

 

address_line_1 = substr(address_line, length(name) + 2);

☑ This topic is solved.

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

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