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!
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.