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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.