BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jeff_DOC
Pyrite | Level 9

I hope someone can give me an assist here.

I have text data in one variable that varies in length. The field begins with a name and contains the word "ZIP" somewhere in the string. I need to find the occurrence of "ZIP" and remove all text after that occurrence to the end of the string.

Is there anyone who could point me in the right direction?

Thank you very much.

Data Have

John M. Smith ZIP 99999 any town any city

Mary M. Smith any town any city ZIP 88888 some other text

Bill Murray title book ZIP

Data Want:

John M. Smith

Mary M. Smith

Bill Murray

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
ballardw
Super User

data want;

     set have;

     string = substr(string,1,(indexw(string,'ZIP')));

run;

Where String is the name of your variable with the text. Note that the search is case sensitive, if you have values of Zip or zip they won't match.

Jeff_DOC
Pyrite | Level 9

This mostly works. However, what I end up with is:

John M. Smith Z

Mary M. Smith Z

Bill Murray Z

ballardw
Super User

,(indexw(string,'ZIP')-1

Jeff_DOC
Pyrite | Level 9

Thank you very, very much. That works perfectly.

Jeff

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 980 views
  • 3 likes
  • 2 in conversation