<?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: Counter Variable without sorting in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479074#M71436</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input VAR_1 $ /;
cards;
A
1
C
1
A
2
B
1
A
3
C
2
;
run;
data want;
if _n_=1 then do;
 if 0 then set have;
 declare hash h();
 h.definekey('var_1');
 h.definedata('count');
 h.definedone();
end;
 set have;
 if h.find()=0 then do;count=count+1;h.replace();end;
  else do;count=1;h.add();end;
run;
 
proc print;run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Jul 2018 14:19:06 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-07-18T14:19:06Z</dc:date>
    <item>
      <title>Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479064#M71435</link>
      <description>&lt;P&gt;I need to create a counter variable which does not have to be sorted. It cannot be sorted as the order is custom on a number of different other criteria, essentially it looks random but isn't in the larger dataset.&amp;nbsp;The output counter would look like below using&amp;nbsp;VAR_1 as the key variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;VAR_1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Counter&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;C&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;B&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;C&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479064#M71435</guid>
      <dc:creator>CharlesFowler72</dc:creator>
      <dc:date>2018-07-18T14:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479074#M71436</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input VAR_1 $ /;
cards;
A
1
C
1
A
2
B
1
A
3
C
2
;
run;
data want;
if _n_=1 then do;
 if 0 then set have;
 declare hash h();
 h.definekey('var_1');
 h.definedata('count');
 h.definedone();
end;
 set have;
 if h.find()=0 then do;count=count+1;h.replace();end;
  else do;count=1;h.add();end;
run;
 
proc print;run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479074#M71436</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-18T14:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479082#M71438</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;glad you posted this.&amp;nbsp; I was thinking, "If only I knew hashing."&amp;nbsp; This is the final piece of evidence that I must learn it.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479082#M71438</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-18T14:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479085#M71439</link>
      <description>&lt;PRE&gt;
Sure. Hash Table is a programming tool you must learn. 

&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 14:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479085#M71439</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-18T14:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479157#M71448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;HR /&gt;&lt;BR /&gt;This is the final piece of evidence that I must learn it.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I can recommend it and I've just noticed that the book "&lt;A href="https://www.sas.com/store/books/categories/examples/data-management-solutions-using-sas-hash-table-operations-a-business-intelligence-case-study/prodBK_69153_en.html" target="_blank"&gt;Data Management Solutions Using SAS® Hash Table Operations: A Business Intelligence Case Study&lt;/A&gt;" by Paul Dorfman and Don Henderson has now been published.&amp;nbsp;It was mentioned in &lt;A href="http://support.sas.com/resources/papers/proceedings17/0821-2017.pdf" target="_blank"&gt;this interesting paper&lt;/A&gt; by the authors, which they called "a preview of [that] SAS book".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I started learning hash object programming there was only Michele M. Burlew's book "&lt;A href="https://www.sas.com/store/books/categories/usage-and-reference/sas-hash-object-programming-made-easy/prodBK_62230_en.html" target="_blank"&gt;SAS® Hash Object Programming Made Easy&lt;/A&gt;". In October 2016 I wrote a customer review (titled "Valuable resource for intermediate and advanced SAS programmers") about it on a very well known online bookseller's website. Since then, the hash object has become one of my must-have tools.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 17:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479157#M71448</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-07-18T17:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Variable without sorting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479529#M71466</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input VAR_1 $ /;
cards;
A
1
C
1
A
2
B
1
A
3
C
2
;
run;

data want;
set have;
array t(3,2) _temporary_;
_k=rank(VAR_1);
_k2=whichn(_k, of t(*));
if _k2=0 then do;_n+1; t(_n,1)=_k;count=1;t(_n,2)=count;end;
else do;count=t(_k2,2)+1;t(_k2,2)=count;end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 14:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Counter-Variable-without-sorting/m-p/479529#M71466</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-19T14:50:23Z</dc:date>
    </item>
  </channel>
</rss>

