<?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: counting observations in by group in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248611#M3665</link>
    <description>&lt;P&gt;PROC FREQ is a great proc for counting occurences. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table Name*Rating/nopct;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Feb 2016 03:08:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-08T03:08:13Z</dc:date>
    <item>
      <title>counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248606#M3663</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have students who get ratings on their courses. I need to know how many total 'Excellent' and 'Satisfactory' each student (by group in this case) got regardless of their course. Can someone help please. Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp;Name &amp;nbsp; Course &amp;nbsp;Skill_Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Rating&lt;/STRONG&gt;&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;English &amp;nbsp;Writing &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Excellent&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;English &amp;nbsp;Listening &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Satisfactory&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;English &amp;nbsp;Learning &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;Biology &amp;nbsp;Writing &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Excellent&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;Biology &amp;nbsp;Listening &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Satisfactory&lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; &amp;nbsp;Biology &amp;nbsp;Learning &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Satisfactory&lt;/P&gt;
&lt;P&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Math &amp;nbsp; &amp;nbsp; Writing &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Excellent&lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Math &amp;nbsp; &amp;nbsp; Listening &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Satisfactory&lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Math &amp;nbsp; &amp;nbsp; Learning &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Biology &amp;nbsp;Writing &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Excellent&lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Biology &amp;nbsp;Listening &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Excellent&lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Biology &amp;nbsp;Learning &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Good&lt;BR /&gt;&lt;BR /&gt;Output table will be:&lt;BR /&gt;ID &amp;nbsp;Name &amp;nbsp; Excellent &amp;nbsp; Satisfactory &lt;BR /&gt;10 Jack &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &lt;BR /&gt;13 Jill &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 02:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248606#M3663</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-02-08T02:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248609#M3664</link>
      <description>&lt;P&gt;proc tabulate data=have;&lt;BR /&gt;class ID Name Rating;&lt;BR /&gt;where rating ne 'Good';&lt;BR /&gt;table id*name,Rating=''*n='';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 02:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248609#M3664</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-02-08T02:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248611#M3665</link>
      <description>&lt;P&gt;PROC FREQ is a great proc for counting occurences. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table Name*Rating/nopct;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Feb 2016 03:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248611#M3665</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-08T03:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248656#M3667</link>
      <description>&lt;P&gt;Assuming you want a data set in the format that you have shown ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your data set is already sorted by ID ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to program it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.ID then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; excellent=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; satisfactory=0;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if rating='Excellent' then excellent + 1;&lt;/P&gt;
&lt;P&gt;else if rating='Satisfactory' then satisfactory + 1;&lt;/P&gt;
&lt;P&gt;if last.ID;&lt;/P&gt;
&lt;P&gt;drop rating;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 13:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248656#M3667</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-08T13:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248686#M3668</link>
      <description>&lt;P&gt;Thanks Reeza, that's really helpful. Can you tell me how do I bring more than one variable to show up in the table. In this case&amp;nbsp;ID&amp;nbsp;in addition to&amp;nbsp;Name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 15:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248686#M3668</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-02-08T15:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: counting observations in by group</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248770#M3672</link>
      <description>&lt;P&gt;If I may step in here: Yes, you can add ID as an additional "factor" to the TABLE statement, in which case it's useful to add the LIST option so as to keep all combinations in one table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;table ID*Name*Rating / nopct list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By using&amp;nbsp;the&amp;nbsp;OUT= option and applying PROC TRANSPOSE to the output dataset, you could even get exactly the output table&amp;nbsp;you had envisaged in your original post:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table ID*Name*Rating / nopct list out=cnt;
run;

proc transpose data=cnt out=want(drop=_:);
where rating in: ('Exc', 'Sat');
by id name;
var count;
id rating;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/counting-observations-in-by-group/m-p/248770#M3672</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-08T23:16:58Z</dc:date>
    </item>
  </channel>
</rss>

