<?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: Create unique category ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781169#M248971</link>
    <description>Why do you need to do work to create a redundant variable named category_ID? What's the point?</description>
    <pubDate>Fri, 19 Nov 2021 01:33:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-11-19T01:33:16Z</dc:date>
    <item>
      <title>Create unique category ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781167#M248969</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without numerous if-then-else statements, how can you create a unique numeric category ID variable from the have data set?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input category $ list $;
datalines;
A Person1
A Person2
A Person3
A Person4
B Person5
B Person6
B Person7
B Person8
C Person9
C Person10
C Person11
C Person12
D Person13
D Person14
D Person15
D Person16
;

data want;
input category_id category $ list $;
datalines;
1 A Person1
1 A Person2
1 A Person3
1 A Person4
2 B Person5
2 B Person6
2 B Person7
2 B Person8
3 C Person9
3 C Person10
3 C Person11
3 C Person12
4 D Person13
4 D Person14
4 D Person15
4 D Person16
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Nov 2021 01:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781167#M248969</guid>
      <dc:creator>rah1992</dc:creator>
      <dc:date>2021-11-19T01:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique category ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781169#M248971</link>
      <description>Why do you need to do work to create a redundant variable named category_ID? What's the point?</description>
      <pubDate>Fri, 19 Nov 2021 01:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781169#M248971</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-19T01:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique category ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781172#M248972</link>
      <description>&lt;P&gt;Also really curious as to why, but this is quite straightforward.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input category $ list $;
want = rank(category) - 64;
datalines;
A Person1
A Person2
A Person3
A Person4
B Person5
B Person6
B Person7
B Person8
C Person9
C Person10
C Person11
C Person12
D Person13
D Person14
D Person15
D Person16
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect this will not scale to your data though so another method to iterate it here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
set have;
by category;
retain grouper 0;
if first.Category then grouper+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401167"&gt;@rah1992&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without numerous if-then-else statements, how can you create a unique numeric category ID variable from the have data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input category $ list $;
datalines;
A Person1
A Person2
A Person3
A Person4
B Person5
B Person6
B Person7
B Person8
C Person9
C Person10
C Person11
C Person12
D Person13
D Person14
D Person15
D Person16
;

data want;
input category_id category $ list $;
datalines;
1 A Person1
1 A Person2
1 A Person3
1 A Person4
2 B Person5
2 B Person6
2 B Person7
2 B Person8
3 C Person9
3 C Person10
3 C Person11
3 C Person12
4 D Person13
4 D Person14
4 D Person15
4 D Person16
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 01:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781172#M248972</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-19T01:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique category ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781187#M248978</link>
      <description>&lt;P&gt;Works great. Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;. Need it to feed into a user-defined macro requiring a numeric unique ID column. Not my macro and don't have time now to edit it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 04:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781187#M248978</guid>
      <dc:creator>rah1992</dc:creator>
      <dc:date>2021-11-19T04:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique category ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781227#M248994</link>
      <description>&lt;P&gt;My solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    numeric_id=rank(category)-rank('A')+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but maybe this fails if you have oversimplified the category variable&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 11:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-unique-category-ID/m-p/781227#M248994</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-19T11:15:52Z</dc:date>
    </item>
  </channel>
</rss>

