<?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: Decoding letters into numbers in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247319#M56290</link>
    <description>&lt;P&gt;If the data is grouped so that all of your records for an ID are together something like this might work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have (rename=(id=oldId));
   by notsorted oldId;
   retain id 0;
   if first.oldid then id+1;
   /* if you don't want the oldid then add:
   drop oldid;
   I wouldn't until verifying everything worked as intended.
   */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or sort by the ID before this data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2016 21:35:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-02-01T21:35:31Z</dc:date>
    <item>
      <title>Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247316#M56287</link>
      <description>&lt;P&gt;I have a variable that is a random combination of letters and numbers and I want to convert it into numbers to give each combination an id number. What I have looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;raw&lt;/P&gt;
&lt;P&gt;0004BG&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0004BG&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0004BG&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;0004BG&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;G45700&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;G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t;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 21:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247316#M56287</guid>
      <dc:creator>katie80</dc:creator>
      <dc:date>2016-02-01T21:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247317#M56288</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input raw $;
cards;
0004BG
0004BG
0004BG
0004BG
G45700
G45700
L43709
L43709
L43709
;

data want;
set have;
by raw;
id+first.raw;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If HAVE is not sorted by RAW, but equal RAW values are grouped, please modify the BY statement to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by raw notsorted;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If HAVE is neither sorted nor grouped, please sort HAVE by RAW before creating WANT.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 21:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247317#M56288</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-01T21:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247318#M56289</link>
      <description>&lt;P&gt;You can use BY group processing to identify your groups. Assuming they're sorted already. BY group processing is very powerful and it's worth reading up a bit on how it works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a specific example for you:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/faq/enumerate.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/faq/enumerate.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And the SAS documentation:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000761932.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000761932.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by ID;

retain count;

if first.ID then count+1;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 21:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247318#M56289</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-01T21:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247319#M56290</link>
      <description>&lt;P&gt;If the data is grouped so that all of your records for an ID are together something like this might work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have (rename=(id=oldId));
   by notsorted oldId;
   retain id 0;
   if first.oldid then id+1;
   /* if you don't want the oldid then add:
   drop oldid;
   I wouldn't until verifying everything worked as intended.
   */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or sort by the ID before this data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 21:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247319#M56290</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-01T21:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247322#M56291</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table id as select
raw,
monotonic() as id
from (select distinct raw from have)
;
run;

create table want as select 
t1.raw,
t2.id
from have t1
left join id t2
on t1.raw = t2.raw
;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A potential SQL solution as well. Not my favorite, but you wouldn't have to sort anything separately.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 21:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247322#M56291</guid>
      <dc:creator>DanZ</dc:creator>
      <dc:date>2016-02-01T21:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding letters into numbers</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247326#M56292</link>
      <description>&lt;P&gt;Thank you! Simple and got the job done.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 22:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Decoding-letters-into-numbers/m-p/247326#M56292</guid>
      <dc:creator>katie80</dc:creator>
      <dc:date>2016-02-01T22:02:18Z</dc:date>
    </item>
  </channel>
</rss>

