I am using the following code to find the word DI. The code below returns true when it looks at "CREDIT". However I want it to return false, DI is in CREDIT, but I only want cases true when DI is a word. How do i achieve this?
if findw(field_to_search_from, 'DI') ge 1 then flag= 1;
I would use the FIND or FINDW functions to identify distinct words.
For example:
DATA _NULL_;
*----+----1----+----2----+----3----+----4----+----5-;
String = 'In Army boot camp, the DI is in charge.';
Position = FINDW(String, 'DI');
PUTLOG "The position is " Position 2.;
RUN;
Yields:
The position is 24
Jim
Please post the code you have including data in usable form (data step with datalines, no attachments).
Using findw is the right choice.
try putting a space before and after like ' DI '
But if CREDIT is the first word in the field_to_search_from then it wont have a space before it?
not unless you write CRE DI T
@Josie1 wrote:
try putting a space before and after like ' DI '
Not necessary if findw is used.
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.