SUPPORT / SAMPLES & SAS NOTES
 

Support

Usage Note 38719: Use PRXMATCH in place of multiple INDEX functions

DetailsAboutRate It

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.



Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemN/ATru64 UNIX9.1 TS1M3
Solaris for x649.1 TS1M3
Solaris9.1 TS1M3
OpenVMS Alpha9.1 TS1M3
Linux on Itanium9.1 TS1M3
Linux for x649.1 TS1M3
Linux9.1 TS1M3
HP-UX IPF9.1 TS1M3
HP-UX9.1 TS1M3
AIX9.1 TS1M3
64-bit Enabled Solaris9.1 TS1M3
64-bit Enabled HP-UX9.1 TS1M3
64-bit Enabled AIX9.1 TS1M3
Windows Vista9.1 TS1M3
Microsoft Windows XP Professional9.1 TS1M3
Microsoft Windows Server 2003 Standard Edition9.1 TS1M3
Microsoft Windows Server 2003 Enterprise Edition9.1 TS1M3
Microsoft Windows Server 2003 Datacenter Edition9.1 TS1M3
Microsoft Windows NT Workstation9.1 TS1M3
Microsoft Windows 2000 Professional9.1 TS1M3
Microsoft Windows 2000 Server9.1 TS1M3
Microsoft Windows 2000 Datacenter Server9.1 TS1M3
Microsoft Windows 2000 Advanced Server9.1 TS1M3
Microsoft Windows XP 64-bit Edition9.1 TS1M3
Microsoft Windows Server 2003 Enterprise 64-bit Edition9.1 TS1M3
Microsoft Windows Server 2003 Datacenter 64-bit Edition9.1 TS1M3
Microsoft® Windows® for 64-Bit Itanium-based Systems9.1 TS1M3
Microsoft® Windows® for x649.1 TS1M3
z/OS9.1 TS1M3
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.