Transform Alphanumeric Codes to Numeric
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * (Q) I have a string variable in which the majority of codes are 2-digit numbers, but some of these contain letters, such as 1A, 2B, etc. Using syntax, I would like to convert the variable to a numeric one, with 1A to 1.1, 2B to 2.2, etc. * (A) By rlevesque@videotron.ca 2001/10/24. DATA LIST LIST /var1(A3). BEGIN DATA 1A 2b 3C 33 4d 5E 6f 7G 85 8H 9i 1B 1F END DATA. LIST. STRING end1(A1) beg1(A3). COMPUTE beg1=SUBSTR(var1,LEN(RTRIM(var1))-1,1). COMPUTE end1=UPCASE(SUBSTR(var1,LEN(RTRIM(var1)))). COMPUTE nb=INDEX("ABCDEFGHI",end1). DO IF nb>0. COMPUTE numb1=NUMBER(beg1,F8.0)+nb/10. ELSE. COMPUTE numb1=NUMBER(var1,F8.0). END IF. EXECUTE. |
Related pages
...