Sample 35010: Iterating through character values in a DATA step DO loop
In order to instruct a DATA step DO loop to iterate from one character value to another, you can use the RANK function to return the position or decimal value of a character in the ASCII or EBCDIC collating sequence. These values would reprsent your start and stop values for the DO loop. To retrieve the corresponding ASCII or EBCDIC character values for use within the DO block of code, you can use the BYTE function.
Here is a link to another sample showing how to iterate through character values within a MACRO %DO loop:
Sample #25961, Using character values on a macro %DO loop
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;
do dec_value = rank('A') to rank('Z');
alpha_value = byte(dec_value);
output;
end;
run;
proc print;
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.
dec_ alpha_
Obs value value
1 65 A
2 66 B
3 67 C
4 68 D
5 69 E
6 70 F
7 71 G
8 72 H
9 73 I
10 74 J
11 75 K
12 76 L
13 77 M
14 78 N
15 79 O
16 80 P
17 81 Q
18 82 R
19 83 S
20 84 T
21 85 U
22 86 V
23 87 W
24 88 X
25 89 Y
26 90 Z
The RANK and BYTE functions can be used to easily iterate through a sequence of character values in a DATA step DO loop.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step
|
Date Modified: | 2009-04-16 13:46:48 |
Date Created: | 2009-03-03 13:15:55 |
Operating System and Release Information
SAS System | Base SAS | Tru64 UNIX | 8.2 TS2M0 | |
Solaris | 8.2 TS2M0 | |
OpenVMS Alpha | 8.2 TS2M0 | |
Linux | 8.2 TS2M0 | |
IRIX | 8.2 TS2M0 | |
HP-UX | 8.2 TS2M0 | |
AIX | 8.2 TS2M0 | |
ABI+ for Intel Architecture | 8.2 TS2M0 | |
64-bit Enabled Solaris | 8.2 TS2M0 | |
64-bit Enabled HP-UX | 8.2 TS2M0 | |
64-bit Enabled AIX | 8.2 TS2M0 | |
Windows Millennium Edition (Me) | 8.2 TS2M0 | |
Microsoft Windows XP Professional | 8.2 TS2M0 | |
Microsoft Windows Server 2003 Standard Edition | 8.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 8.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 8.2 TS2M0 | |
Microsoft Windows NT Workstation | 8.2 TS2M0 | |
Microsoft Windows 2000 Professional | 8.2 TS2M0 | |
Microsoft Windows 2000 Server | 8.2 TS2M0 | |
Microsoft Windows 2000 Datacenter Server | 8.2 TS2M0 | |
Microsoft Windows 2000 Advanced Server | 8.2 TS2M0 | |
Microsoft Windows 95/98 | 8.2 TS2M0 | |
OS/2 | 8.2 TS2M0 | |
OpenVMS VAX | 8.2 TS2M0 | |
z/OS | 8.2 TS2M0 | |