<?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: Generate max count variable, across observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11581#M1397</link>
    <description>Great!  Worked perfectly.&lt;BR /&gt;
Thanks a lot.&lt;BR /&gt;
&lt;BR /&gt;
Andy</description>
    <pubDate>Fri, 27 Mar 2009 14:30:44 GMT</pubDate>
    <dc:creator>awc380</dc:creator>
    <dc:date>2009-03-27T14:30:44Z</dc:date>
    <item>
      <title>Generate max count variable, across observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11579#M1395</link>
      <description>Hi!&lt;BR /&gt;
&lt;BR /&gt;
I'm trying to generate a specific 'count' variable (I know...aren't we all), and I know how to do basic count variable (as below), but I want the variable 's_count' to equal the total count for each observation, generated by 'id'.  &lt;BR /&gt;
&lt;BR /&gt;
I can get part of the way there, but I need the 's_count' variable to have no missing observations.  i.e.: in the chart below, 's_count' SHOULD read (1,2,2,3,3,3) - I need 's_count' to show the number of observations having the same id number.  (A sample fraction, of sorts.)&lt;BR /&gt;
&lt;BR /&gt;
num id count s_count&lt;BR /&gt;
&lt;BR /&gt;
 1   a   1      1&lt;BR /&gt;
 2   b   1      .&lt;BR /&gt;
 3   b   2      2&lt;BR /&gt;
 4   c   1      .&lt;BR /&gt;
 5   c   2      .&lt;BR /&gt;
 6   c   3      3&lt;BR /&gt;
&lt;BR /&gt;
This was the best I could do.  Here was my data step:&lt;BR /&gt;
&lt;BR /&gt;
data ds2;&lt;BR /&gt;
set ds1;&lt;BR /&gt;
count + 1;&lt;BR /&gt;
by id;&lt;BR /&gt;
if first.id then count = 1;&lt;BR /&gt;
if last.id then s_count = count;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
Let me know if I'm being entirely unclear...</description>
      <pubDate>Thu, 26 Mar 2009 17:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11579#M1395</guid>
      <dc:creator>awc380</dc:creator>
      <dc:date>2009-03-26T17:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Generate max count variable, across observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11580#M1396</link>
      <description>Many ways to do this. Simplest would be:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table tot_count as&lt;BR /&gt;
select *, max(count) as s_count&lt;BR /&gt;
from ds2&lt;BR /&gt;
group by id;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
ie dont do the s_count in the datastep.&lt;BR /&gt;
&lt;BR /&gt;
even easier:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table ds2 as&lt;BR /&gt;
select *, count(*) as s_count&lt;BR /&gt;
from ds1&lt;BR /&gt;
group by id;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
from the basic data.</description>
      <pubDate>Thu, 26 Mar 2009 17:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11580#M1396</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T17:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Generate max count variable, across observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11581#M1397</link>
      <description>Great!  Worked perfectly.&lt;BR /&gt;
Thanks a lot.&lt;BR /&gt;
&lt;BR /&gt;
Andy</description>
      <pubDate>Fri, 27 Mar 2009 14:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-max-count-variable-across-observations/m-p/11581#M1397</guid>
      <dc:creator>awc380</dc:creator>
      <dc:date>2009-03-27T14:30:44Z</dc:date>
    </item>
  </channel>
</rss>

