Sample 41182: Use the IN operator with arrays to check for the existence of a value
In releases of SAS® prior to SAS® 9.1, if you wanted to check for the existence
of a value within an element of an array, you needed to use an iterative DO loop to cycle through each element of the array.
Beginning with SAS 9.1, you can use the IN operator with only the name of the array to easily perform the same operation.
See the Full Code tab for an illustration of the syntax using the IN operator with the array name.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data test;
/* Define and initialize a character and numeric array. */
array char_values[3] $3 ('abc', 'def', 'ghi');
array num_values[3] (1, 2, 3);
/* Use the IN operator with only the name of the array to test */
/* for the existence of a value in any element of the array. */
if 'abc' in char_values then found_abc = 1;
else found_abc = 0;
if 'xyz' in char_values then found_xyz = 1;
else found_xyz = 0;
if 2 in num_values then found_2 = 1;
else found_2 = 0;
if 5 in num_values then found_5 = 1;
else found_5 = 0;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
char_ char_ char_ num_ num_ num_ found_ found_
Obs values1 values2 values3 values1 values2 values3 abc xyz found_2 found_5
1 abc def ghi 1 2 3 1 0 1 0
The IN operator can be used with the name of an array to determine whether a specific value exists in any element of the array.
| Date Modified: | 2010-10-11 13:24:07 |
| Date Created: | 2010-10-11 08:45:15 |
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9.1 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M0 | |
| Microsoft Windows 2000 Advanced Server | 9.1 TS1M0 | |
| Microsoft Windows 2000 Datacenter Server | 9.1 TS1M0 | |
| Microsoft Windows 2000 Server | 9.1 TS1M0 | |
| Microsoft Windows 2000 Professional | 9.1 TS1M0 | |
| Microsoft Windows NT Workstation | 9.1 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M0 | |
| Microsoft Windows XP Professional | 9.1 TS1M0 | |
| 64-bit Enabled AIX | 9.1 TS1M0 | |
| 64-bit Enabled HP-UX | 9.1 TS1M0 | |
| 64-bit Enabled Solaris | 9.1 TS1M0 | |
| HP-UX IPF | 9.1 TS1M0 | |
| Linux | 9.1 TS1M0 | |
| OpenVMS Alpha | 9.1 TS1M0 | |
| Tru64 UNIX | 9.1 TS1M0 | |