![]() | ![]() | ![]() | ![]() |
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.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | N/A | Tru64 UNIX | 9.1 TS1M3 | |
Solaris for x64 | 9.1 TS1M3 | |||
Solaris | 9.1 TS1M3 | |||
OpenVMS Alpha | 9.1 TS1M3 | |||
Linux on Itanium | 9.1 TS1M3 | |||
Linux for x64 | 9.1 TS1M3 | |||
Linux | 9.1 TS1M3 | |||
HP-UX IPF | 9.1 TS1M3 | |||
HP-UX | 9.1 TS1M3 | |||
AIX | 9.1 TS1M3 | |||
64-bit Enabled Solaris | 9.1 TS1M3 | |||
64-bit Enabled HP-UX | 9.1 TS1M3 | |||
64-bit Enabled AIX | 9.1 TS1M3 | |||
Windows Vista | 9.1 TS1M3 | |||
Microsoft Windows XP Professional | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |||
Microsoft Windows NT Workstation | 9.1 TS1M3 | |||
Microsoft Windows 2000 Professional | 9.1 TS1M3 | |||
Microsoft Windows 2000 Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |||
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |||
Microsoft® Windows® for x64 | 9.1 TS1M3 | |||
z/OS | 9.1 TS1M3 |