<?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: Adding a new column to a sas table with the number of records in each group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701257#M214719</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input ID $   Yr;
cards;
A    2003

A    2004

A    2004

B    2003

B    2003
;

proc sql;
 create table want as
 select *, count(*) as occurences
 from have
 group by id
 order by id, yr;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Nov 2020 15:31:13 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-11-24T15:31:13Z</dc:date>
    <item>
      <title>Adding a new column to a sas table with the number of records in each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701253#M214717</link>
      <description>&lt;P&gt;Suppose I have a SAS table as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Yr&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2003&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2004&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2004&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; 2003&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; 2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add a new column which has the number of occurrences of each ID as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;Yr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Occurences&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2003&amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2004&amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; 2004&amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; 2003&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; 2003&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise on how I can do this&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 15:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701253#M214717</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2020-11-24T15:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to a sas table with the number of records in each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701257#M214719</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input ID $   Yr;
cards;
A    2003

A    2004

A    2004

B    2003

B    2003
;

proc sql;
 create table want as
 select *, count(*) as occurences
 from have
 group by id
 order by id, yr;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 15:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701257#M214719</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-24T15:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to a sas table with the number of records in each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701260#M214721</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  occurences=sum(occurences,1);
 end;
 do _n_=1 to _n_;
  set have;
  output;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 15:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701260#M214721</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-24T15:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to a sas table with the number of records in each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701262#M214722</link>
      <description>&lt;P&gt;That worked perfectly. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 15:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-to-a-sas-table-with-the-number-of-records-in/m-p/701262#M214722</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2020-11-24T15:33:51Z</dc:date>
    </item>
  </channel>
</rss>

