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

Hello,

 

I am trying to search an 80 character variable in my dataset called PROCDUCT and categorize its contents. For example, I'd like to search PRODUCT for any of the words related to a book (paperback, volume, etc) and then create a new product variable that contains with word BOOK for that record. I've tried FIND and FINDW but its not returning the results I'm looking for.  What is the best way to go about this? 

 

Thank you. 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You could use regular expression matching, such as

 

isBook = prxMatch("/\b(paperback|volume|book\b/i", PRODUCT);

if isBook then productKind = "Book";

 

 

PG

View solution in original post

6 REPLIES 6
Reeza
Super User
One approach is to split each product to the word level, summarize and categorize the words according to PROC FREQ summaries and subject matter expertise and then add flags. You can then transpose the sentence back with the flags for the terms of interest.

joesmama
Obsidian | Level 7

That sounds like it might work. I'm not familiar with how to do that. Can you point me in the right direction please? Thanks. 

PGStats
Opal | Level 21

You could use regular expression matching, such as

 

isBook = prxMatch("/\b(paperback|volume|book\b/i", PRODUCT);

if isBook then productKind = "Book";

 

 

PG
joesmama
Obsidian | Level 7

Thank you. I've tried that and it keeps coming back blank. I've tried with FINDW as well and that comes back blank or empty as well. Am I missing something? . Why would it come back as blank? Alsp, my string is actually 232 characters long. Appreciate your help. 

PGStats
Opal | Level 21

Show us an example of what you tried. Regular expression matching is a great tool for dealing with text. It is worth spending the time to learn how it works.

PG
joesmama
Obsidian | Level 7

Looks like one of my parentheses was out of order. It worked like  a charm. Thank you!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 841 views
  • 0 likes
  • 3 in conversation