<?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: Count the number of times a ky appeared individually in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620486#M182337</link>
    <description>Thanks!</description>
    <pubDate>Tue, 28 Jan 2020 13:25:02 GMT</pubDate>
    <dc:creator>iSAS</dc:creator>
    <dc:date>2020-01-28T13:25:02Z</dc:date>
    <item>
      <title>Count the number of times a key appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620466#M182322</link>
      <description>&lt;P&gt;Let's say I have a data below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile cards truncover;&lt;BR /&gt;input ID :$4.;&lt;BR /&gt;cards;&lt;BR /&gt;0196&lt;BR /&gt;0196&lt;BR /&gt;0196&lt;BR /&gt;0395&lt;BR /&gt;0752&lt;BR /&gt;1277&lt;BR /&gt;1277&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is to have a new table with a new column wherein it will count the number of times the ID appeared but not group it. To explain it clearer, I want to have an output like this:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count_ID&lt;BR /&gt;0196&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;0196&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;0196&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;0395&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;0752&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;1277&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;1277&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone help me on this? A program that will work even if ID is not sort by order&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 12:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620466#M182322</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2020-01-28T12:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of times a ky appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620468#M182324</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set Have;
  Count_ID + 1;
  By ID;
  if first.ID then Count_ID = 1;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 11:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620468#M182324</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-01-28T11:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of times a ky appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620469#M182325</link>
      <description>&lt;P&gt;As requested, this works regardless of the sort order&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    if _N_=1 then do;
        declare hash h();
        h.definekey('id');
        h.definedata('Count_ID');
        h.definedone();
    end;

    set have;

    if h.find() ne 0 then Count_ID = 1;
    else                  Count_ID + 1;

    h.replace();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID    Count_ID 
0196  1 
0196  2 
0196  3 
0395  1 
0752  1 
1277  1 
1277  2 
&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 12:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620469#M182325</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-28T12:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of times a key appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620481#M182331</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132557"&gt;@iSAS&lt;/a&gt;&amp;nbsp; For unsorted count, Hash is easy and convenient. While the sorted and Hash&amp;nbsp; solutions have already been posted, I was thinking what if your ID are all digits and do have any alpha char. If this is true, key indexing is very viable and yet another convenient solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
infile cards truncover;
input ID :$4.;
cards;
0196
0196
0196
0395
0752
1277
1277
;
run;

data want;
 do until(z);
  set have end=z;
  array t(999999)_temporary_;
  _n_=input(id,32.);
  if t(_n_) then t(_n_)=sum(t(_n_),1);
  else t(_n_)=1;
  count_id=t(_n_);
  output;
 end;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jan 2020 13:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620481#M182331</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-28T13:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of times a key appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620485#M182336</link>
      <description>Thanks!</description>
      <pubDate>Tue, 28 Jan 2020 13:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620485#M182336</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2020-01-28T13:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count the number of times a ky appeared individually</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620486#M182337</link>
      <description>Thanks!</description>
      <pubDate>Tue, 28 Jan 2020 13:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-the-number-of-times-a-key-appeared-individually/m-p/620486#M182337</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2020-01-28T13:25:02Z</dc:date>
    </item>
  </channel>
</rss>

