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.
You could use regular expression matching, such as
isBook = prxMatch("/\b(paperback|volume|book\b/i", PRODUCT);
if isBook then productKind = "Book";
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.
You could use regular expression matching, such as
isBook = prxMatch("/\b(paperback|volume|book\b/i", PRODUCT);
if isBook then productKind = "Book";
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.
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.
Looks like one of my parentheses was out of order. It worked like a charm. Thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.