Select cases where same letter appears twice in string
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 | *(Q) I have a string variable with many different characters (ABCDEFAGHI). * I would like to select each case that has 2 instances of a particular character (character A in my sample above). The characters are not always in the same location in the string. How can I do this? Thanks for any help. *(A) Posted by Raynald Levesque to spss newsgroup on 2001/12/10. * This syntax flags any case for which a letter (any letter) occurs more than once in the string of interest. DATA LIST /str 1-14(A). BEGIN DATA ABCDEFAGHI DBCDEFZGHI ZBCDEFAGHI ABCDEFGHI ABCDEFGHIJH END DATA. LIST. STRING #char (A1). LOOP cnt=1 TO 14. COMPUTE #char=SUBSTR(str,cnt,1). LOOP cnt2=cnt + 1 TO 14. DO IF #char=SUBSTR(str,cnt2,1) & #char<>" ". + COMPUTE flag=1. + BREAK. END IF. END LOOP. END LOOP. EXECUTE. * The cases where flag=1 are those you want. |
Related pages
...