<?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 Count of specific observations by ID and Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707667#M217303</link>
    <description>&lt;P&gt;I'm not sure of the best approach for this, so I'll provide a current table example and the desired output table. The first table is a series of records. The activity types are known, so I'm thinking we could use WHERE ActivityType = "App_New". But am open to any and all suggestions/help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;ActivityType&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm looking to accomplish, is to count the number of specific activity types by ID and by Date. So the "new" table would look something like this (see below), based off the above table.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Total_App_New&lt;/TD&gt;&lt;TD&gt;Total_App_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 22 Dec 2020 14:19:18 GMT</pubDate>
    <dc:creator>BlayLay</dc:creator>
    <dc:date>2020-12-22T14:19:18Z</dc:date>
    <item>
      <title>Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707667#M217303</link>
      <description>&lt;P&gt;I'm not sure of the best approach for this, so I'll provide a current table example and the desired output table. The first table is a series of records. The activity types are known, so I'm thinking we could use WHERE ActivityType = "App_New". But am open to any and all suggestions/help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;ActivityType&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;APP_New&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm looking to accomplish, is to count the number of specific activity types by ID and by Date. So the "new" table would look something like this (see below), based off the above table.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Total_App_New&lt;/TD&gt;&lt;TD&gt;Total_App_Edit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/01/2020&lt;/TD&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;B123D&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;A932F&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11/02/2020&lt;/TD&gt;&lt;TD&gt;C456E&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707667#M217303</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2020-12-22T14:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707672#M217306</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
  input ID $5. Date :mmddyy10. ActivityType $9.;
  format Date date.;
  datalines;
B123D 11/01/2020 APP_New
B123D 11/01/2020 APP_New
A932F 11/01/2020 APP_Edit
C456E 11/01/2020 APP_New
B123D 11/02/2020 APP_Edit
A932F 11/02/2020 APP_New
C456E 11/02/2020 APP_Edit
C456E 11/02/2020 APP_New
;
run;

proc sort data=input;
  by date id  ActivityType;
run;

data output;
  set input;
  by date id ;
  retain Total_App_New Total_App_Edit;

  if first.id then 
    do; 
      Total_App_New=0;
      Total_App_Edit=0;
    end;

  if ActivityType = 'APP_New' then Total_App_New+1;
  else if ActivityType = 'APP_Edit' then Total_App_Edit+1;

  if last.id then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="count.png" style="width: 210px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52961i2BC6407AFFEE856A/image-size/large?v=v2&amp;amp;px=999" role="button" title="count.png" alt="count.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 14:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707672#M217306</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2020-12-22T14:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707680#M217312</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349857"&gt;@BlayLay&lt;/a&gt;&amp;nbsp; You could resort to lazy way of doing it by utilizing Proc Freq SPARSE option and a simple transpose. Increasingly I am getting used to these methods-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
  input ID $5. Date :mmddyy10. ActivityType $9.;
  format Date date9.;
  datalines;
B123D 11/01/2020 APP_New
B123D 11/01/2020 APP_New
A932F 11/01/2020 APP_Edit
C456E 11/01/2020 APP_New
B123D 11/02/2020 APP_Edit
A932F 11/02/2020 APP_New
C456E 11/02/2020 APP_Edit
C456E 11/02/2020 APP_New
;
run;

proc freq data=input;
 tables date*id*ActivityType/sparse noprint out=temp(drop=percent);
run;

proc transpose data=temp out=want(drop=_:) prefix=Total_;
 by date id;
 var count;
 id ActivityType;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707680#M217312</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-22T15:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707686#M217316</link>
      <description>&lt;P&gt;Great&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good use of &lt;A title="reports all possible combinations of variable values in two-way and multiway tables, even if a combination does not occur in the data. This option applies only to crosstabulation tables that are displayed in LIST format and to OUT= output data sets." href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_freq_syntax08.htm&amp;amp;docsetVersion=15.2&amp;amp;locale=en#statug.freq.freqsparse" target="_self"&gt;sparse&lt;/A&gt; - Was not aware of this one - very useful - thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707686#M217316</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2020-12-22T15:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707688#M217318</link>
      <description>&lt;P&gt;Ditto&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13642"&gt;@GertNissen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Great&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Good use of &lt;A title="reports all possible combinations of variable values in two-way and multiway tables, even if a combination does not occur in the data. This option applies only to crosstabulation tables that are displayed in LIST format and to OUT= output data sets." href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_freq_syntax08.htm&amp;amp;docsetVersion=15.2&amp;amp;locale=en#statug.freq.freqsparse" target="_self"&gt;sparse&lt;/A&gt; - Was not aware of this one - very useful - thanks&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 15:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707688#M217318</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-22T15:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707697#M217322</link>
      <description>Thank you! This worked perfectly</description>
      <pubDate>Tue, 22 Dec 2020 16:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707697#M217322</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2020-12-22T16:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707867#M217415</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
  input ID $5. Date :mmddyy10. ActivityType $9.;
  format Date date9.;
  datalines;
B123D 11/01/2020 APP_New
B123D 11/01/2020 APP_New
A932F 11/01/2020 APP_Edit
C456E 11/01/2020 APP_New
B123D 11/02/2020 APP_Edit
A932F 11/02/2020 APP_New
C456E 11/02/2020 APP_Edit
C456E 11/02/2020 APP_New
;
run;
proc sql noprint;
select distinct cats("sum(ActivityType='",ActivityType,"') as total_",ActivityType)
 into : list separated by ','
  from input;
create table want as
select date,id,&amp;amp;list 
 from input
  group by date,id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Dec 2020 12:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707867#M217415</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-12-23T12:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count of specific observations by ID and Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707950#M217458</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;&amp;nbsp; , &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13642"&gt;@GertNissen&lt;/a&gt;&amp;nbsp; for the note.&amp;nbsp; To be totally honest, I was taught these tricks by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; a while ago. Of course I tend to take notes of such geniuses , and this being yet another that PG advised me to quickly grasp three major equivalent options i.e-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc FREQ- SPARSE&lt;/P&gt;
&lt;P&gt;Proc Summary/Means - COMPLETETYPES&lt;/P&gt;
&lt;P&gt;Proc REPORT- COMPLETEROWS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp; Whether you remember or not, Thank you sharing this that now these learning are nicely shared across the our platform. Cheers!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2020 18:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-of-specific-observations-by-ID-and-Date/m-p/707950#M217458</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-23T18:39:19Z</dc:date>
    </item>
  </channel>
</rss>

