Hello all, I have a piece of code where it looks at an ID variable that should only have numbers in it. But I created some test data where the IDs are messed up and have some letters in it. The goal is to transform the letters (a, b, c...) into zeros (0). The code does the job well if and only if there is only the same type of character in the string. Example: 551215A becomes 5512150 57A1215 becomes 5701215 55Cc13c becomes 5500130. But IDs like: 55Aab5A became 55AA05A (Only the B was transformed to zero - I would like it to be 5500050) abCDE5g became ABCDE50 (only the G was transformed to zero - I would like it to be 0000050). That is, only the last letter the do loop sees in the observation gets transformed to zero. Bellow follows the code: /*///////////////////////////////////////////////////////////*/ DATA test_id; INPUT claimid $; DATALINES; 551215A 55Cc13c 541215B abCDE5g 551B159 6512157 57A1215 55Aab5A 5682154 581915c 5519155 ; run; DATA test_id2; set test_id (rename = (claimid = orig_claimid)); claim_num = orig_claimid + 0; claimid = upcase(orig_claimid); do i = 'A', 'B', 'C', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'; if claim_num = . and (index(claimid,i) > 0) then do; claim_use = tranwrd(claimid,i,'0'); end; end; if claim_use = '' then do; claim_use = claimid; end; drop i; run; proc print data = test_id2; run; /*///////////////////////////////////////////////////////////*/ I would appreciate any ideas on how to get the code to transform all letters in the string into zeros. Thank you for your hep. Alex
... View more