DATA Step, Macro, Functions and more

How to remove part of a word?

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

How to remove part of a word?

Hi,

I have a data with a variable City and that includes Boroughs. I don't want to have Borough in the City and want to take of the Borough from the City. How can I do that? , I used compress but it is not working the way I want the output to be.

 

E.g.

 

City

Albany

Delmar

Troy

Borough of Bronx

Borough of Queens

Borough of Brooklyn

Manhattan

Buffalo

Suffolk

Nassau

 

 

I don't want "Borough of" and only want to display it as Bronx or Queens etc. I have around more than 100 observations with different City names. I can't use 100 if-then statements. Is there a easy way to do this.

 

Thank you

M

 


Accepted Solutions
Solution
‎01-31-2018 09:10 AM
Super User
Super User
Posts: 9,193

Re: How to remove part of a word?

Posted in reply to Malathi13
want=strip(tranwrd(have,"Borough of",""));

View solution in original post


All Replies
Solution
‎01-31-2018 09:10 AM
Super User
Super User
Posts: 9,193

Re: How to remove part of a word?

Posted in reply to Malathi13
want=strip(tranwrd(have,"Borough of",""));
Contributor
Posts: 73

Re: How to remove part of a word?

Hi RW9,

I just used tranwrd without strip and it worked perfectly as I wanted and you gave the same with strip. Thank you so much for the answer. This saved me a lot of time and writing a long code.

 

M

Contributor
Posts: 37

Re: How to remove part of a word?

Posted in reply to Malathi13

Hi,

 

Here in this case you can even try 

 

want=scan(city,-1);

 

Thanks

☑ This topic is solved.

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

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