<?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: Converting a character including number to unique number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466356#M118990</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/96795"&gt;@dincooo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your answer.&lt;/P&gt;
&lt;P&gt;Actually these are passport numbers and I think there are&amp;nbsp;no passport numbers with exactly the same char-number combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following your logic consider below case. Is that what you want?&lt;/P&gt;
&lt;TABLE width="358"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="172"&gt;Original Passport Number&lt;/TD&gt;
&lt;TD width="186"&gt;Converted Passport Number&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A2345&lt;/TD&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12C45&lt;/TD&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 08:11:41 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-05-31T08:11:41Z</dc:date>
    <item>
      <title>Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466344#M118983</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a party_number varible which may contain records like these: A12345 , 123E45 , 67588H.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to&amp;nbsp;change the character letters with their alphabetic order numbers.&lt;/P&gt;&lt;P&gt;For example A is the first character of the alphabet and I want to convert A12345 to 112345.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123E45&amp;nbsp; ==&amp;gt; 123545&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;67588H ==&amp;gt; 675888&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I do this with SAS coding?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Onur&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 07:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466344#M118983</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2018-05-31T07:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466346#M118984</link>
      <description>&lt;P&gt;You can use the rank() procedure:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0m5k2s76pmv9pn1n1lu3vfyq8s4.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0m5k2s76pmv9pn1n1lu3vfyq8s4.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will return the number of the character in its position in the character table, so A is 65, you can then just remove 64 to get 1, B would be 66, so -64 = 2 etc.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 07:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466346#M118984</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T07:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466350#M118986</link>
      <description>&lt;P&gt;There are several ways to do this, though&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;s solution is probably the best.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you say you want to make the number unique? What if you have two occurrences of the value&amp;nbsp;&lt;SPAN&gt;A12345? Then they will both be converted to&amp;nbsp;112345 and will not be unique?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 07:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466350#M118986</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-05-31T07:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466352#M118987</link>
      <description>&lt;P&gt;Thank you very much for your answer.&lt;/P&gt;&lt;P&gt;Actually these are passport numbers and I think there are&amp;nbsp;no passport numbers with exactly the same char-number combination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rank function can be used but char values may be in the beggining, middle etc.. how I take the char value, convert to number and put it to record?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 07:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466352#M118987</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2018-05-31T07:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466355#M118989</link>
      <description>&lt;P&gt;A string is just an array of characters, so:&lt;/P&gt;
&lt;PRE&gt;data want;
  infile datalines;
  length pp_no new_ppno $20;
  input ppno $;
  do i=1 to lengthn(ppno);
    if anyalpha(char(ppno,i)) then substr(new_ppno,i,1)=put(rank(char(ppno,i))-64,1.);
    else substr(new_ppno,i,1)=char(ppno,i);
  end;
datalines;
A1234
23F56
12345
;
run; &lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 08:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466355#M118989</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T08:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466356#M118990</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/96795"&gt;@dincooo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your answer.&lt;/P&gt;
&lt;P&gt;Actually these are passport numbers and I think there are&amp;nbsp;no passport numbers with exactly the same char-number combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following your logic consider below case. Is that what you want?&lt;/P&gt;
&lt;TABLE width="358"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="172"&gt;Original Passport Number&lt;/TD&gt;
&lt;TD width="186"&gt;Converted Passport Number&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A2345&lt;/TD&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12C45&lt;/TD&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466356#M118990</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-31T08:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466396#M118999</link>
      <description>&lt;P&gt;What if you have these passport numbers:&lt;/P&gt;
&lt;PRE&gt;A54321
15432A&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;And what wiIl you do with characters K and following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 11:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466396#M118999</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-31T11:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466397#M119000</link>
      <description>&lt;P&gt;No it is a case which i dont want. So i missed that point. Do you have any idea how can make these passport numbers as unique number?&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 11:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466397#M119000</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2018-05-31T11:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466405#M119002</link>
      <description>&lt;P&gt;I missed that point you're right..&lt;/P&gt;&lt;P&gt;Do you have any other suggestion how can i make passport numbers unique?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All suggestions are more than welcome &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 11:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466405#M119002</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2018-05-31T11:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466410#M119006</link>
      <description>&lt;P&gt;Sort a distinct list of passports, then assign a unique number:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=uniques nodupkey;
  by passport_no;
run;

data uniques (keep=passport_no passport_unique);
  set uniques;
  passport_unique=_n_;
run;

data want;
  merge have uniques;
  by passport_no;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 12:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466410#M119006</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T12:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466422#M119009</link>
      <description>&lt;P&gt;It depends on what you want to do. As a unique key, your current passport numbers are already perfect.&lt;/P&gt;
&lt;P&gt;And keys are stored as strings, not as numbers.&lt;/P&gt;
&lt;P&gt;Numbers are only needed for calculations, and I don't see any useful calculation done with passport numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to deal with both of the problems I mentioned:&lt;/P&gt;
&lt;P&gt;Start your number with the position of the character in the string, and code the character into two digits (01 go 26).&lt;/P&gt;
&lt;P&gt;Another: extract the PP numbers to a new dataset and assign them a sequential number (_n_). Then use that lookup dataset to recode.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 12:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466422#M119009</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-31T12:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466512#M119034</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/96795"&gt;@dincooo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a party_number varible which may contain records like these: A12345 , 123E45 , 67588H.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to&amp;nbsp;change the character letters with their alphabetic order numbers.&lt;/P&gt;
&lt;P&gt;For example A is the first character of the alphabet and I want to convert A12345 to 112345.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;123E45&amp;nbsp; ==&amp;gt; 123545&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;67588H ==&amp;gt; 675888&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can I do this with SAS coding?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks,&lt;/P&gt;
&lt;P&gt;Onur&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is length assigned to the variable? What is longest (character count) of values in the current variable? I ask because if your variable has a length of 6, as implied by your example data and you have one or more letters J or later&amp;nbsp;in the alphabet then you will be replacing one character with two for each letter. And the result may not fit your original variable and would require either a new variable or additional steps to change the length of your current variable.&lt;/P&gt;
&lt;P&gt;Here is a very basic example:&lt;/P&gt;
&lt;PRE&gt;data example;
   x='J'; /* x has length of 1*/
   x='10'; /* attempt to assign 10 instead of J*/
   put x=; /* x has value of '1' in the data set*/
run;&lt;/PRE&gt;
&lt;P&gt;If your value currently has 6 characters and may contain all 6 as letters then you need something that will hold at least 12 characters as the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 15:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466512#M119034</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-31T15:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a character including number to unique number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466662#M119092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/96795"&gt;@dincooo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;No it is a case which i dont want. So i missed that point. Do you have any idea how can make these passport numbers as unique number?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use the passport numbers alphanumeric directly as keys. I don't see any reason why they would need to be numeric.&lt;/P&gt;
&lt;P&gt;But you can of course also generate an additional key.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to go is to just sort by passport number and then count unique groups.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by passport_no;
  if first.passport_no then passport_id+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This approach is totally fine if that's an adhoc task. If you need to implement some sort of ETL process where you might want to load additional passport records later on, then you would of course need some lookup process to only create additional passport id's if they don't exist already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively: Generate a hash key. Functions like MD5() or SHA() can be used for this. These functions will always return the same output value for the same input value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  passport_no='A1234';
  passport_id=put(md5(pp_no),hex32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 22:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-character-including-number-to-unique-number/m-p/466662#M119092</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-31T22:43:30Z</dc:date>
    </item>
  </channel>
</rss>

