Sample 33227: Using the IN operator to determine whether a numeric or character value exists within a group of variables
When trying to determine whether a specific value exists within a group of variables, a common approach is to associate the variables with an ARRAY and then use a DO loop to loop through every element or variable in the ARRAY. As an example, here is a segment of code:
array my_array[*] var1 - var10;
do i = 1 to dim(my_array);
if some_value = my_array[i] then found = 'Yes';
end;
A more efficient alternative is to use the IN operator with the name of the ARRAY and avoid using the DO loop. This can be done with both numeric ARRAYS as well as character ARRAYS. Here is a code segment:
array my_array[*] var1 - var10;
if some_value IN my_array then found = 'Yes';
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.
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.
The IN operator can be used with an ARRAY name to efficiently determine whether a value exists within any of the variables associated with the ARRAY.
Type: | Sample |
Topic: | SAS Reference ==> Statements ==> Information ==> ARRAY SAS Reference ==> Statements ==> Information ==> Array Reference
|
Date Modified: | 2008-09-16 13:52:02 |
Date Created: | 2008-09-09 11:04:52 |
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 | |