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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1093 views
  • 0 likes
  • 3 in conversation