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
,(indexw(string,'ZIP')-1
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.
This mostly works. However, what I end up with is:
John M. Smith Z
Mary M. Smith Z
Bill Murray Z
,(indexw(string,'ZIP')-1
Thank you very, very much. That works perfectly.
Jeff
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.