<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: replacing letters with numbers in a character variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137012#M36914</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, Patrick. In theory there shouldn't be letters in this variable, so if it happen I definitely would have to separate those records and inquire as to what's going on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But for the sake of exercise, data_null_'s response works like a charm and does what I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, guys!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Nov 2013 23:40:11 GMT</pubDate>
    <dc:creator>avbraga</dc:creator>
    <dc:date>2013-11-08T23:40:11Z</dc:date>
    <item>
      <title>replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137008#M36910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;551215A becomes 5512150&lt;/P&gt;&lt;P&gt;57A1215 becomes 5701215&lt;/P&gt;&lt;P&gt;55Cc13c becomes 5500130.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But IDs like:&lt;/P&gt;&lt;P&gt;55Aab5A became 55AA05A (Only the B was transformed to zero - I would like it to be 5500050)&lt;/P&gt;&lt;P&gt;abCDE5g became ABCDE50 (only the G was transformed to zero - I would like it to be 0000050). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, only the last letter the do loop sees in the observation gets transformed to zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bellow follows the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*///////////////////////////////////////////////////////////*/&lt;/P&gt;&lt;P&gt;DATA test_id; &lt;/P&gt;&lt;P&gt;INPUT claimid $;&lt;/P&gt;&lt;P&gt;DATALINES; &lt;/P&gt;&lt;P&gt;551215A&lt;/P&gt;&lt;P&gt;55Cc13c&lt;/P&gt;&lt;P&gt;541215B&lt;/P&gt;&lt;P&gt;abCDE5g&lt;/P&gt;&lt;P&gt;551B159&lt;/P&gt;&lt;P&gt;6512157&lt;/P&gt;&lt;P&gt;57A1215&lt;/P&gt;&lt;P&gt;55Aab5A&lt;/P&gt;&lt;P&gt;5682154&lt;/P&gt;&lt;P&gt;581915c&lt;/P&gt;&lt;P&gt;5519155&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA test_id2; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set test_id (rename = (claimid = orig_claimid));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; claim_num = orig_claimid + 0;&lt;/P&gt;&lt;P&gt; claimid = upcase(orig_claimid); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 'A', 'B', 'C', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z';&lt;/P&gt;&lt;P&gt;&amp;nbsp; if claim_num = . and (index(claimid,i) &amp;gt; 0) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; claim_use = tranwrd(claimid,i,'0');&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if claim_use = '' then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; claim_use = claimid;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data = test_id2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;/*///////////////////////////////////////////////////////////*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 23:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137008#M36910</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-11-08T23:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137009#M36911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;translate(upcase(claimid),repeat('0',25),'ABCDEFGHIJKLMNIOQRSTUVWXYZ');&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 23:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137009#M36911</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-11-08T23:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137010#M36912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you know why there are letters in your claim id's? You need a proper explanation for this before transforming such id's or you risk to fold multiple id's into one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;claimed_num=input(prxchange('s/[^\d ]/0/oi',-1,claimid),best32.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 23:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137010#M36912</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-08T23:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137011#M36913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data_null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that's beautiful my friend. Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 23:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137011#M36913</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-11-08T23:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137012#M36914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, Patrick. In theory there shouldn't be letters in this variable, so if it happen I definitely would have to separate those records and inquire as to what's going on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But for the sake of exercise, data_null_'s response works like a charm and does what I want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, guys!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2013 23:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137012#M36914</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2013-11-08T23:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: replacing letters with numbers in a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137013#M36915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A PRX approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA test_id;&lt;/P&gt;&lt;P&gt;INPUT claimid $;&lt;/P&gt;&lt;P&gt;_new=prxchange('s/[a-z]/0/io',-1,claimid);&lt;/P&gt;&lt;P&gt;DATALINES;&lt;/P&gt;&lt;P&gt;551215A&lt;/P&gt;&lt;P&gt;55Cc13c&lt;/P&gt;&lt;P&gt;541215B&lt;/P&gt;&lt;P&gt;abCDE5g&lt;/P&gt;&lt;P&gt;551B159&lt;/P&gt;&lt;P&gt;6512157&lt;/P&gt;&lt;P&gt;57A1215&lt;/P&gt;&lt;P&gt;55Aab5A&lt;/P&gt;&lt;P&gt;5682154&lt;/P&gt;&lt;P&gt;581915c&lt;/P&gt;&lt;P&gt;5519155&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Nov 2013 02:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/replacing-letters-with-numbers-in-a-character-variable/m-p/137013#M36915</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-11-09T02:07:25Z</dc:date>
    </item>
  </channel>
</rss>

