Use PRXMATCH in place of multiple INDEX functions


If you need to search a character variable for multiple different substrings, the conventional method is to link several INDEX function calls together with OR conditions:

    if index(lowcase(charvar),'this') > 0 or 
       index(lowcase(charvar),'that') > 0 or
       index(lowcase(charvar),'other') > 0 then found = 1;
    else found=0; 

The PRXMATCH function, for Perl Regular Expressions Match, can do it all in a single call. This requires less typing and fewer chances for mistakes:

    if prxmatch("m/this|that|other/oi",charvar) > 0 then found=1;
    else found=0; 

The 'm' tag at the beginning of the search string tells PRXMATCH that it is doing a matching operation. This is the default. The 'o' tag at the end tells SAS to compile the parse string once. This is also the default because the parse string is a constant. The 'i' tag at the end forces a case insensitive match so that "THIS" is equal to "this" for the purpose of matching. The pipes separate the search strings. Do not add spaces unless they are part of the matching criteria because every character counts.

For more information, see PRXMATCH in the Functions section of the SAS Language Reference: Dictionary in the Online SAS Documentation.