<?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 specific observations within groups of observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638588#M78179</link>
    <description>&lt;P&gt;Try this! replace the text in bold with your dataset name.&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(distinct(enum)) into: count_event&lt;BR /&gt;from &lt;STRONG&gt;&amp;lt;datasetname&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;where ObserverID in ('02','05')&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;%put count_event = &amp;amp;count_event;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2020 05:16:54 GMT</pubDate>
    <dc:creator>vkumbhakarna</dc:creator>
    <dc:date>2020-04-09T05:16:54Z</dc:date>
    <item>
      <title>Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638567#M78178</link>
      <description>&lt;DIV&gt;&lt;FONT&gt;This is probably simple but....I don't know how to do it.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;My dataset consists of Events recorded by multiple Observers.&amp;nbsp; I want a count of Events observed by both ObserverID 02 and 05.&amp;nbsp; See below...&amp;nbsp; Thanks in advance!&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;ENum&amp;nbsp;ObserverID&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0G&lt;BR /&gt;1&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&amp;nbsp;05&lt;BR /&gt;1&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;&lt;FONT&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;04&lt;BR /&gt;2&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&amp;nbsp;05&lt;BR /&gt;2&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&amp;nbsp;02&lt;BR /&gt;3&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&amp;nbsp;0A&lt;BR /&gt;3&lt;FONT&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/FONT&gt;&lt;FONT&gt;&amp;nbsp;&lt;/FONT&gt; 0P&lt;BR /&gt;3&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;4&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0D&lt;BR /&gt;4&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0J&lt;BR /&gt;4&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;5&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0D&lt;BR /&gt;5&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0M&lt;BR /&gt;5&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0H&lt;BR /&gt;5&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;6&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0H&lt;BR /&gt;6&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0M&lt;BR /&gt;6&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;7 &lt;FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/FONT&gt; 0G&lt;BR /&gt;7&lt;FONT&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/FONT&gt; 05&lt;BR /&gt;7&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;8&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0A&lt;BR /&gt;8&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0P&lt;BR /&gt;8&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;02&lt;BR /&gt;9&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0J&lt;BR /&gt;9&amp;nbsp;&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;0G&lt;BR /&gt;9&lt;FONT&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&amp;nbsp;02&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Apr 2020 04:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638567#M78178</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2020-04-09T04:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638588#M78179</link>
      <description>&lt;P&gt;Try this! replace the text in bold with your dataset name.&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(distinct(enum)) into: count_event&lt;BR /&gt;from &lt;STRONG&gt;&amp;lt;datasetname&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;where ObserverID in ('02','05')&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;%put count_event = &amp;amp;count_event;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 05:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638588#M78179</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-09T05:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638589#M78180</link>
      <description>&lt;P&gt;You can merge subsets of the same data set.&lt;/P&gt;
&lt;PRE&gt;data want (keep=enum label='Enums observed by 02 and 05');
  merge 
    have (where=(ObserverID='02') in = _02)
    have (where=(ObserverID='05') in = _05)
    end=end
  ;
  by enum;

  _0205_flag = first.enum and _02 and _05;  * use first. in case the field data has repeated information;

  count + _0205_flag;

  if end then put 'NOTE: ' count ' enums observed by both 02 and 05';

  if _0205_flag;  * subsetting if;
run;
&lt;/PRE&gt;
&lt;P&gt;In SQL you can count a positive logical assertion over a group using SUM&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select enum from have
  group by enum
  having sum(ObserverId='02') &amp;gt; 0 and sum(ObserverId='05') &amp;gt; 0;&lt;BR /&gt;&lt;BR /&gt;%put NOTE: &amp;amp;SQLOBS enums were dual observed by 02 and 05;&lt;/PRE&gt;
&lt;P&gt;A NODUPKEY SORT + DATA step can find the enums that were dual observed&lt;/P&gt;
&lt;PRE&gt;proc sort nodupkey data=have out=_0205 ;
  by enum ObserverId;
  where ObserverId in ('02' '05');
run;

data want;
  set _0205;
  by enum;
  if last.enum and not first.enum;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 22:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638589#M78180</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-09T22:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638598#M78181</link>
      <description>&lt;P&gt;You have not explained in which form the result is required in. If you want the number in a macro-variable, the proc sql suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11920"&gt;@vkumbhakarna&lt;/a&gt; is the way to go. If you want it in a dataset, you could use proc summary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
	where ObserverID in ('02', '05');
	output out=counted(drop=_type_ rename=(_freq_=count));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Apr 2020 06:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638598#M78181</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-09T06:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638628#M78182</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;assuming that ENum is integer and you are able to anticipate its range, following should do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ENum ObserverID $;
cards;

1         0G
1          05
1          02
2         04
2          05
2          02
3          0A
3           0P
3          02
4          0D
4          0J
4          02
5          0D
5          0M
5          0H
5          02
6          0H
6          0M
6          02
7          0G
7          05
7          02
8          0A
8          0P
8          02
9          0J
9          0G
9          02
;
run;

data want;
  array obs2[9] _temporary_;
  array obs5[9] _temporary_;

  do until (EOF);
    set have end = eof;
      where observerID in ('02', '05');
    select;
      when(observerID = '02') obs2[ENum] = 1;
      when(observerID = '05') obs5[ENum] = 1;
      otherwise;
    end;
  end;

  do ENum = 1 to 9;
    count + (obs2[ENum] and obs5[ENum]);
  end;
  output;
  keep count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if ENum isn't integer or you can't anticipate the range then following should do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  declare hash obs2();
  obs2.defineKey("ENum");
  obs2.defineDone();
  declare hiter I2("obs2");

  declare hash obs5();
  obs5.defineKey("ENum");
  obs5.defineDone();

  do until (EOF);
    set have end = eof;
      where observerID in ('02', '05');
    select;
      when(observerID = '02') _N_ = obs2.add();
      when(observerID = '05') _N_ = obs5.add();
      otherwise;
    end;
  end;

  do while(I2.next() = 0);
    if obs5.check() = 0 then count + 1;
  end;&lt;BR /&gt;  output;&lt;BR /&gt;  keep count;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or eventually:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as  
  select count(*) from  
    (
    select ENum from have where observerID = '02'
    intersect
    select ENum from have where observerID = '05' 
    )
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 10:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638628#M78182</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-09T10:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638692#M78183</link>
      <description>&lt;P&gt;Hi Bart &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would call your second hash way a 'hash merge'.&amp;nbsp; This was my take on it.&lt;/P&gt;
&lt;PRE&gt;data want(keep=enum label='They have been watching you');
  retain enum .;

  declare hash _02(dataset:'have(where=(ObserverID = "02"))', ordered:'A');
  declare hash _05(dataset:'have(where=(ObserverID = "05"))', ordered:'A');

  _02.defineKey('enum'); _02.defineDone();
  _05.defineKey('enum'); _05.defineDone();

  declare hiter check ('_02');
  do while (check.next() eq 0);
    if _05.check()=0 then do;
      _0205_pair_count + 1;
      output;
    end;
  end;

  put 'NOTE: There are ' _0205_pair_count 'enums that were observed by 02 and 05';
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Apr 2020 15:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638692#M78183</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-09T15:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638693#M78184</link>
      <description>Great use of INTERSECT !</description>
      <pubDate>Thu, 09 Apr 2020 15:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638693#M78184</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-09T15:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638698#M78185</link>
      <description>&lt;P&gt;Nice! I'm making a copy in my archive.&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 15:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638698#M78185</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-09T15:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638717#M78186</link>
      <description>&lt;P&gt;These solutions worked too.&amp;nbsp; The one using INTERSECT is really slick!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gene&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 16:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638717#M78186</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2020-04-09T16:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638756#M78187</link>
      <description>&lt;P&gt;Wow! i'm loving these forums. Get to learn something new every day.&lt;/P&gt;
&lt;P&gt;Liked the use of&amp;nbsp;&lt;SPAN&gt;SQLOBS. Per documentation, SQLOBS automatic macro variable is assigned a value after the SQL SELECT statement executes. PROC SQL produces six automatic macro variables (SQLOBS, SQLRC, SQLOOPS, SQLEXITCODE, SQLXRC, and SQLXMSG) to help you troubleshoot your program.&amp;nbsp;For more information, see&amp;nbsp;&lt;A class="" tabindex="0" title="" href="https://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1cyzuadeotccqn1hwfdtmwejh2w" data-docset-id="sqlproc" data-docset-version="9.4" data-original-href="p0xlnvl46zgqffn17piej7tewe7p.htm#p1cyzuadeotccqn1hwfdtmwejh2w"&gt;Using the PROC SQL Automatic Macro Variables&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 17:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638756#M78187</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-09T17:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638812#M78188</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect the &lt;A href="https://communities.sas.com/t5/Community-Memo/SAS-Support-Communities-Updates-are-here/ba-p/632750" target="_blank" rel="noopener"&gt;new forum software&lt;/A&gt; has jumbled a few lines of the DATA step with your MERGE approach: The "&lt;FONT face="courier new,courier"&gt;if end then put ...&lt;/FONT&gt;" must have been moved upwards from its original place after the sum statement. Now it would be executed prematurely if the last BY group contributed to the count.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 21:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638812#M78188</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-09T21:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638827#M78189</link>
      <description>Good catch.  I'll fix the answer.  In order to have the END= based logging PUT in the step, there needs to be some more scaffolding before the subsetting IF.</description>
      <pubDate>Thu, 09 Apr 2020 22:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638827#M78189</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-04-09T22:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638886#M78201</link>
      <description>Hi,&lt;BR /&gt;using the example data your code returns 9 - but expected is 3. Requirement was "count of Events observed by both ObserverID 02 and 05" what is not equivalent to condition `where ObserverID in ('02','05')` (i.e. ObserverID = '02' OR ObserverID = '05').&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Bart</description>
      <pubDate>Fri, 10 Apr 2020 07:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/638886#M78201</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-10T07:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/639059#M78211</link>
      <description>&lt;P&gt;Thanks! Yes, I realized my mistake after reading the other responses. I misinterpreted the initial question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 21:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/639059#M78211</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-10T21:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count specific observations within groups of observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/639121#M78213</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Richard,&lt;/P&gt;
&lt;P&gt;I've just realised that for this task you need no more than 1 hash table (or 1 array)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue primes
  '02'  = 2
  '05'  = 5
  other = 1
  ;
run;&lt;BR /&gt;
data _null_;
  if 0 then set have;
  declare hash obs(hashexp:20);
  obs.defineKey("ENum");
  obs.defineData("ENum","INT");
  obs.defineDone();

  do until (EOF);
    set have end = eof;
    where observerID in ('02', '05');

    if obs.find() NE 0 then
      INT = input(observerID, primes.);
    else
      INT = INT * input(observerID, primes.);
    _N_ = obs.replace();
  end;

  /* if INT is divisible by 10 then ENum was observed by 02 nad 05*/
  obs.output(dataset:'want(where=( mod(INT, 10) = 0 ))');
  stop;
run;


%let range = 9;
data want;
  array obs[&amp;amp;range.] _temporary_;
    do ENum = 1 to &amp;amp;range.;
      obs[ENum] = 1;
    end;

  do until (EOF);
    set have end = eof;
    where observerID in ('02', '05');

    obs[ENum] = obs[ENum] * input(observerID, primes.);

  end;

  do ENum = 1 to &amp;amp;range.;
    if mod(obs[ENum], 10) = 0 then output;
  end;
  keep ENum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Apr 2020 05:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-specific-observations-within-groups-of-observations/m-p/639121#M78213</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-11T05:52:37Z</dc:date>
    </item>
  </channel>
</rss>

