<?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 repeated variables by group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471887#M70949</link>
    <description>&lt;P&gt;NOT WORKING&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jun 2018 20:09:28 GMT</pubDate>
    <dc:creator>Barkamih</dc:creator>
    <dc:date>2018-06-20T20:09:28Z</dc:date>
    <item>
      <title>count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471857#M70944</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;herd                     cow_id
10                           101
10                           101
10                           101
10                           101
10                           101
10                           101 
10                           101
10                           102
10                           102
10                           102
10                           102
10                           103
10                           104
10                           104
10                           104
10                           105
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           107
11                           107
11                           108
11                           108
11                           108
11                           108
11                           108
11                           108
11                           108 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I just wanted to count the number&amp;nbsp;of cow_id for each herd that I have in my dataset.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Data named: Fatd&amp;nbsp; and&amp;nbsp; &amp;nbsp; I have variable herd and coe_id,&amp;nbsp; I want to delete all herds that have less than 5 cow_ids.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at this data, Herd 10 has 5 cows ID (101, 102, 103, 104, 105). the repetition 7 times of&amp;nbsp; cow_id 101 mean this cow has 7 times of measurements, so in my question,&amp;nbsp;I don't care about&amp;nbsp;the repetition, I'm just looking for cow_id.&amp;nbsp; &amp;nbsp;And herd 11 has 3 cows ID (106, 107, 108), so in this case, I just want to keep herd 10 and delete herd 11, it does not matter how much each cow had been repeated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just care about the number of cows in each herd not about the number&amp;nbsp;of measurements.&amp;nbsp; (Repeated cow_id is a different time of measurements).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you get my idea this time&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;&lt;P&gt;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;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 19:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471857#M70944</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T19:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471865#M70945</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input herd cow_id;
datalines;
10 101
10 101
10 101
10 101
10 101
10 101
10 101
10 102
10 102
10 102
10 102
10 103
10 104
10 104
10 104
10 105
11 106
11 106
11 106
11 106
11 106
11 106
11 106
11 106
11 106
11 107
11 107
11 108
11 108
11 108
11 108
11 108
11 108
11 108
;

proc sql;
   create table want as
   select * from have
   where herd in 
   (select distinct herd from have group by herd having count(distinct cow_id) &amp;gt;= 5);
quit;
                  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 19:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471865#M70945</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-06-20T19:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471866#M70946</link>
      <description>&lt;P&gt;proc sort data=....;&lt;/P&gt;&lt;P&gt;by herd cow_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ....&lt;/P&gt;&lt;P&gt;retain count;&lt;/P&gt;&lt;P&gt;set ....;&lt;/P&gt;&lt;P&gt;by herd cow_id;&lt;/P&gt;&lt;P&gt;if first.herd then count=1;&lt;/P&gt;&lt;P&gt;if first.cow_id then count=count+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does that work?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 19:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471866#M70946</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-06-20T19:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471869#M70947</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input herd                     cow_id;
cards;
10                           101
10                           101
10                           101
10                           101
10                           101
10                           101 
10                           101
10                           102
10                           102
10                           102
10                           102
10                           103
10                           104
10                           104
10                           104
10                           105
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           106
11                           107
11                           107
11                           108
11                           108
11                           108
11                           108
11                           108
11                           108
11                           108 
;

proc sql;
create table want as
select *
from have
group by herd
having  count(distinct cow_id)&amp;gt;=5;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 19:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471869#M70947</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-20T19:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471885#M70948</link>
      <description>&lt;P&gt;My dataset over million, how I can put them in the code, I'm sorry about this but I'm new with SAS.&lt;/P&gt;&lt;P&gt;REGARDS&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471885#M70948</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T20:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471887#M70949</link>
      <description>&lt;P&gt;NOT WORKING&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471887#M70949</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T20:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471891#M70950</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151600"&gt;@Barkamih&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;NOT WORKING&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When someone says "NOT WORKING", this gives us NO information on what has gone wrong, and so there's no way for us to help further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give us information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us your SASLOG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us a part of the results that indicate a problem.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471891#M70950</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-20T20:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471893#M70951</link>
      <description>&lt;P&gt;You don't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You reference your SAS data set. We use cards/datalines to create example data to test the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151600"&gt;@Barkamih&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My dataset over million, how I can put them in the code, I'm sorry about this but I'm new with SAS.&lt;/P&gt;
&lt;P&gt;REGARDS&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471893#M70951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-20T20:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471894#M70952</link>
      <description>&lt;P&gt;Sorry about this, I was so stressful because&amp;nbsp;I have a deadline&amp;nbsp;soon.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this id the error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1273&lt;BR /&gt;1274&lt;BR /&gt;1275&lt;BR /&gt;1276 data FATD&lt;BR /&gt;1277&lt;BR /&gt;1278 retain count;&lt;BR /&gt;------&lt;BR /&gt;56&lt;BR /&gt;ERROR 56-185: RETAIN is not allowed in the DATA statement when option DATASTMTCHK=COREKEYWORDS.&lt;BR /&gt;Check for a missing semicolon in the DATA statement, or use DATASTMTCHK=NONE.&lt;/P&gt;&lt;P&gt;1279&lt;BR /&gt;1280 set FATD;&lt;BR /&gt;1281&lt;BR /&gt;1282 by herd cow_id;&lt;BR /&gt;1283&lt;BR /&gt;1284 if first.herd then count=1;&lt;BR /&gt;1285&lt;BR /&gt;1286 if first.cow_id then count=count+1;&lt;BR /&gt;1287&lt;BR /&gt;1288 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471894#M70952</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T20:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471902#M70953</link>
      <description>You're missing a semicolon.&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471902#M70953</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-20T20:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471903#M70954</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151600"&gt;@Barkamih&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;1276 data FATD&lt;BR /&gt;1277&lt;BR /&gt;1278 retain count;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Put a semi-colon after data FATD&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471903#M70954</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-20T20:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471909#M70955</link>
      <description>&lt;P&gt;Yes I found&amp;nbsp; that&amp;nbsp;&lt;/P&gt;&lt;P&gt;but Nothing change in data as this log showing&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;408 proc sort data=FATD;&lt;BR /&gt;409&lt;BR /&gt;410 by herd cow_id;&lt;BR /&gt;411&lt;BR /&gt;412 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1519417 observations read from the data set WORK.FATD.&lt;BR /&gt;NOTE: The data set WORK.FATD has 1519417 observations and 55 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 3.11 seconds&lt;BR /&gt;cpu time 1.86 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;413&lt;BR /&gt;414&lt;BR /&gt;415&lt;BR /&gt;416 data FATD;&lt;BR /&gt;417&lt;BR /&gt;418 retain count;&lt;BR /&gt;419&lt;BR /&gt;420 set FATD;&lt;BR /&gt;421&lt;BR /&gt;422 by herd cow_id;&lt;BR /&gt;423&lt;BR /&gt;424 if first.herd then count=1;&lt;BR /&gt;425&lt;BR /&gt;426 if first.cow_id then count=count+1;&lt;BR /&gt;427&lt;BR /&gt;428 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1519417 observations read from the data set WORK.FATD.&lt;BR /&gt;NOTE: The data set WORK.FATD has 1519417 observations and 55 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 9.37 seconds&lt;BR /&gt;cpu time 1.71 seconds&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>Wed, 20 Jun 2018 20:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471909#M70955</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T20:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471915#M70957</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/151600"&gt;@Barkamih&lt;/a&gt;&amp;nbsp; May i ask why haven't you tried&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;sql solution in the first place ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471915#M70957</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-20T20:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471919#M70958</link>
      <description>&lt;P&gt;Thank you every one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;my&amp;nbsp; best regards to all of you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brakmih&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 20:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/471919#M70958</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-20T20:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: count repeated variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/472195#M70984</link>
      <description>&lt;P&gt;That what I used to solve my issue!!!!!!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jun 2018 16:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/count-repeated-variables-by-group/m-p/472195#M70984</guid>
      <dc:creator>Barkamih</dc:creator>
      <dc:date>2018-06-21T16:23:22Z</dc:date>
    </item>
  </channel>
</rss>

