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

Greetings Community

 

I have a very simple/quick question:

 

I have a column of the data that contains text. Within that text, I need to look if there is a specific text. My data looks like this:

IDItem
12345BTennis Shoes
2325hgSocks
SD4587XYZ Shoe
D235FOther

 

I need the new data to look like this (please note the third observation is shoe and not shoes):

IDItemShoes
12345BTennis ShoesYes
2325hgSocksNo
SD4587XYZ ShoeYes
D235FOtherNo

 

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Does case matter, i.e. does shoes=Shoes?  If so you might want to upcase.  

if index(upcase(item),"SHOES") then shoes="Yes";

I am sure this isn't your full problem though is it?  Only one word being checked?

View solution in original post

3 REPLIES 3
SuryaKiran
Meteorite | Level 14

use FIND() or INDEX() function if you need to search for a single word. If you have to search for multiple words then use PRXMATCH() function.

 

something like:

 

If FIND(item,'shoe','i')>0 then shoes='YES';else shoes='NO';

 

 

Thanks,
Suryakiran
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Does case matter, i.e. does shoes=Shoes?  If so you might want to upcase.  

if index(upcase(item),"SHOES") then shoes="Yes";

I am sure this isn't your full problem though is it?  Only one word being checked?

altijani
Quartz | Level 8

Right. I just needed a lead for this issue. It is much more than that.

Many thanks though

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1017 views
  • 0 likes
  • 3 in conversation