You can use the find function to do this.
data have;
set want;
if find(comment,"storm","i")>0 then output = "Storm";
else if find(comment,"theft","i")>0 then output = "Theft";
run;
This assumes you will only ever find one or the other. If it is possible to have both, you would have to check for both simultaneously and concatenate your results.
You can use the find function to do this.
data have;
set want;
if find(comment,"storm","i")>0 then output = "Storm";
else if find(comment,"theft","i")>0 then output = "Theft";
run;
This assumes you will only ever find one or the other. If it is possible to have both, you would have to check for both simultaneously and concatenate your results.
The IFC function can also be used to consolidate. In this case i choose to look for either or both.
data have;
input Id $ @5 Comment $30.;
datalines;
1A. GL THE BOAT STORM
2A. SUNSHINE
3A. STORM IN THE CITY
4A. THEFT. IN THE JUNGLE
5A. RAINY DAY
6A. THEFT
7A. THEFT IN A STORM
run;
data want;
set have;
output=catx(',',ifc(index(comment,'STORM'),'storm',' '),ifc(index(comment,'THEFT'),'theft',' '));
run;
An issue to consider: do you want the exact word only, or variations such as THEFTS, RAINSTORM, STORMY ...
Depending on your answer, you might switch from FIND to FINDW.
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.