<?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 Freq group count in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603630#M76475</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a big dataset (cows data) and I would like to know how many herds in each county in each month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data looks like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  
datelines;
county    herd  month 
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    12    Fed
London    11    Fed
London    12    Fed
London    11    Fed
London    12    Fed
London    12    Fed
London    11    Mar
London    12    Mar
London    13    Mar
London    11    Mar
London    12    Mar
London    14    Mar&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And what I need to count the frequency of herd in each month by county and the results should be like this;&lt;/P&gt;&lt;P&gt;county&amp;nbsp; &amp;nbsp; &amp;nbsp;month&amp;nbsp; &amp;nbsp; &amp;nbsp;number of herds&amp;nbsp;&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; Jan&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 Herd&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; Feb&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 herds&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; &amp;nbsp;Mar&amp;nbsp; &amp;nbsp; &amp;nbsp; 4 herds&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I need a code to count frequencies of herds for each month in each county.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What My code should look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ibrahim&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2019 17:01:06 GMT</pubDate>
    <dc:creator>Barkamih</dc:creator>
    <dc:date>2019-11-12T17:01:06Z</dc:date>
    <item>
      <title>Freq group count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603630#M76475</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a big dataset (cows data) and I would like to know how many herds in each county in each month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data looks like this;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  
datelines;
county    herd  month 
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    12    Fed
London    11    Fed
London    12    Fed
London    11    Fed
London    12    Fed
London    12    Fed
London    11    Mar
London    12    Mar
London    13    Mar
London    11    Mar
London    12    Mar
London    14    Mar&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And what I need to count the frequency of herd in each month by county and the results should be like this;&lt;/P&gt;&lt;P&gt;county&amp;nbsp; &amp;nbsp; &amp;nbsp;month&amp;nbsp; &amp;nbsp; &amp;nbsp;number of herds&amp;nbsp;&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; Jan&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 Herd&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; Feb&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 herds&lt;/P&gt;&lt;P&gt;London&amp;nbsp; &amp;nbsp; &amp;nbsp;Mar&amp;nbsp; &amp;nbsp; &amp;nbsp; 4 herds&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I need a code to count frequencies of herds for each month in each county.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What My code should look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ibrahim&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 17:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603630#M76475</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2019-11-12T17:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Freq group count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603637#M76479</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data example;
input county $   herd  month $;
datAlines;
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    11    Jan
London    12    Fed
London    11    Fed
London    12    Fed
London    11    Fed
London    12    Fed
London    12    Fed
London    11    Mar
London    12    Mar
London    13    Mar
London    11    Mar
London    12    Mar
London    14    Mar
;

proc sql;
create table want as
select county,month, count (distinct herd) as num_of_herds
from example
group by county, month;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select county,month, catx(' ',count (distinct herd),'herds') as num_of_herds
from example
group by county, month;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 17:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603637#M76479</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-12T17:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Freq group count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603641#M76480</link>
      <description>&lt;P&gt;&amp;nbsp;Thaaaaaaaaaaaaaaaaaaaaaaaaaaaanks million&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's done&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;working perfectly&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best wishes&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 17:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603641#M76480</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2019-11-12T17:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Freq group count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603730#M76483</link>
      <description>&lt;P&gt;Another approach is two proc freq calls:&lt;/P&gt;
&lt;PRE&gt;proc freq data=example noprint;
tables county*herd*month/out=work.firstcount;
run;
proc freq data=work.firstcount;
tables county*month/list;
run;&lt;/PRE&gt;
&lt;P&gt;However the sort order is based on text so Jan does not appear before Feb.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 23:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Freq-group-count/m-p/603730#M76483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-12T23:36:42Z</dc:date>
    </item>
  </channel>
</rss>

