<?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: PROC SQL counts by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557129#M155272</link>
    <description>&lt;P&gt;Sorry for the late reply.&amp;nbsp; I want to count the numbers of tasks done. If worker works on main and re-do task, this only count as 1. e.g. worker 1 works on task: 1234 and 1234R001, this counts as 1 task done. e.g.&amp;nbsp;worker 1 works on task: 1234S001 (note that main task id can be 4 or 8 or more digits) and 1234S001R001, this counts as 1 task done.&amp;nbsp; e.g. worker 2 works only on task: 1234R001, this counts as 1 task done (consider as independent task even worker 2 didn't work on main task 1234).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the expected result will be worker 1 has 5 tasks done, worker 2 has 3 tasks done.&lt;/P&gt;</description>
    <pubDate>Wed, 08 May 2019 14:22:45 GMT</pubDate>
    <dc:creator>sasecn</dc:creator>
    <dc:date>2019-05-08T14:22:45Z</dc:date>
    <item>
      <title>PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556865#M155160</link>
      <description>&lt;P&gt;I am trying to count of tasks done by workers' id (id variable in the data). The tasks can have sub-tasks. If one works on main and sub tasks, it should only count as 1 task done. If one only works on sub task (without working on main task), it also should count as 1 task done. In the example, worker 1 works on tasks: a, a_s, b. So, 2 tasks done; worker 2 works on: a_s, b. So, also 2 tasks done (even not working on main task: a). My sql code only can capture worker 1's count, but not worker 2 since i cannot find a way to identify who works on sub tasks only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See code below, please help, thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input id $ task_id $ sub_task;
datalines;
1 a 0
1 a_s 1
1 b 0
2 a_s 1
2 b 0
;
run;

proc sql;
  create table out as
    select *, 
	       count(distinct case when not sub_task then task_id end) as done
	from test
	group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 16:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556865#M155160</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556882#M155172</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&amp;nbsp; &amp;nbsp;Should your pattern of subtask follow a pattern such that it takes the value of main_task with a suffix _s , extracting the first char would make it easy. In any event, you can apply the same logic accordingly&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data test;
  input id $ task_id $ sub_task;
datalines;
1 a 0
1 a_s 1
1 b 0
2 a_s 1
2 b 0
;
run;

proc sql;
create table want as
select *,count( distinct first(task_id)) as done
from test
group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 17:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556882#M155172</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T17:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556894#M155180</link>
      <description>&lt;P&gt;Hello:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the mistake. I tried to make the code simple. But the real task id has more chars. e.g. the main task id is 2019-ABC-MAIN-1234; the sub task is&amp;nbsp;2019-ABC-MAIN-1234-S001 (or can be 2019-ABC-MAIN-1234-S001-S002). It is true that the sub task always like&amp;nbsp; &amp;nbsp; "main task id"-S001 ( or ....-S001-S002-... ).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think the first() works. Sorry for making it more complex.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 17:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556894#M155180</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T17:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556896#M155181</link>
      <description>&lt;P&gt;I expected something like that. Can you post a comprehensive sample so that the very logic can be adjusted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic is still the same i.e to get the grouped pattern and count the distinct. Now you need to let us know the values that's a good representative of your sample.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 17:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556896#M155181</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T17:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556902#M155183</link>
      <description>&lt;P&gt;Okay, i tried to manage to get the last 4 digits from my task_id, and now the ids will be 4 digits followed by sub numbers, see example code. There is no special pattern in the 4 digits. Hope this make sense. So, worker 1 should have 7 tasks done.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   informat id task_id $25. sub_task;
   input id task_id sub_task;
   datalines;
1 1234 0
1 1234S001 1
1 1234S001S002 1
1 3456 0
1 9685 0
1 3648 0
1 8888 0
1 2222 0
1 3366 0
2 1234S001 1
2 5678 0
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 18:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556902#M155183</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T18:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556904#M155184</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;STRONG&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&lt;/STRONG&gt;Thank you for the response&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;"now the ids will be 4 digits followed by sub numbers"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this mean a Task or a subtask will conform to a&amp;nbsp; given 4 digit number? Example 1234 series? If this is true, this in itself is a pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;"There is no special pattern in the 4 digits"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think we are looking at any special pattern. The logic is basically to group Taskid and sub task into one group. That's all.&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, 07 May 2019 18:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556904#M155184</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T18:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556910#M155186</link>
      <description>&lt;P&gt;You are right that the task id is always 4 digits number + sub number. The sub number could be S001 or S001S002, .... but always ended as SXXX. The reason i used distinct key work is because there are some duplicates records e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1234 0&lt;/P&gt;&lt;P&gt;1 1234 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is that i cannot find a way to handle workers who only works on sub tasks but not the main one. e.g. worker 2 works on task 1234S001, it should count as 1 independent task. But my original code miss-count this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this make sense?&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 18:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556910#M155186</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T18:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556912#M155188</link>
      <description>&lt;P&gt;&lt;STRONG&gt;"You are right that the &lt;U&gt;task id is always 4 digits number&amp;nbsp;"&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, so this goes back to my original idea, where in the same first 4 digits of all tasks will form one group. Sub numbers are not relevant to this logic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   informat id task_id $25. sub_task;
   input id task_id sub_task;
   datalines;
1 1234 0
1 1234S001 1
1 1234S001S002 1
1 3456 0
1 9685 0
1 3648 0
1 8888 0
1 2222 0
1 3366 0
2 1234S001 1
2 5678 0
;
RUN;

proc sql;
create table want as
select *, count(distinct substr(task_id,1,4)) as done
from test
group by id;
quit;
 &lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 18:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556912#M155188</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T18:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556919#M155193</link>
      <description>&lt;P&gt;Alright, i got your idea. Thx, that works in my situation. Now, i understand what you meant the pattern. I will run into other format of the task ids. Hope this does not bother you too much.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will have to deal with another situation that have to handle different format of ids. For example, the main id will be either 4 digits or 8 digits, and this will be followed by another 4 digits that identify the status of required to redo the task. e.g.&lt;/P&gt;&lt;P&gt;for task 1234, required redo it then the full task id will be 1234R001, for task 1234S001 (8 digits main id) required redo, full id is 1234S001R001. Again, i want to count the tasks done, if worker 1 works on 1234 and 1234R001, this counts as 1 task done. if worker 1 works 1234S001 and 1234S001R001, this also counts as 1. if worker 2 only works on 1234R001, this counts as 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will still have problems to count worker 2. What will be the idea to handle this? Sorry to bother you a lot.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   informat id task_id $25. redo_task;
   input id task_id redo_task;
   datalines;
1 1234 0
1 1234R001 1
1 1234S001 0
1 1234S001R002 1
1 3456 0
1 9685 0
1 3648 0
2 1234S001R001 1
2 1234R001 1
2 5678 0
;
RUN;

proc sql;
  create table out as
    select *, 
	       count(distinct case when not redo_task then task_id end) as done
	from test
	group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 19:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556919#M155193</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T19:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556922#M155196</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&amp;nbsp; &amp;nbsp;No bother at all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically to give you a clear pic of how the logic works is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking your latest sample,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the following your expected result ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.T1" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;task_id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;t&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;grp&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234R001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234S001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234S001R002&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;3456&lt;/TD&gt;
&lt;TD class="l data"&gt;3456&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;9685&lt;/TD&gt;
&lt;TD class="l data"&gt;9685&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;3648&lt;/TD&gt;
&lt;TD class="l data"&gt;3648&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;1234S001R001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;1234R001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;5678&lt;/TD&gt;
&lt;TD class="l data"&gt;5678&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 May 2019 19:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556922#M155196</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-07T19:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556940#M155203</link>
      <description>&lt;P&gt;Sorry, rush into something else. Will get back to you later.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 21:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/556940#M155203</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-07T21:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557129#M155272</link>
      <description>&lt;P&gt;Sorry for the late reply.&amp;nbsp; I want to count the numbers of tasks done. If worker works on main and re-do task, this only count as 1. e.g. worker 1 works on task: 1234 and 1234R001, this counts as 1 task done. e.g.&amp;nbsp;worker 1 works on task: 1234S001 (note that main task id can be 4 or 8 or more digits) and 1234S001R001, this counts as 1 task done.&amp;nbsp; e.g. worker 2 works only on task: 1234R001, this counts as 1 task done (consider as independent task even worker 2 didn't work on main task 1234).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the expected result will be worker 1 has 5 tasks done, worker 2 has 3 tasks done.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 14:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557129#M155272</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-08T14:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557158#M155279</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt;&amp;nbsp; Looks like the problem here is for us to&amp;nbsp;&lt;STRONG&gt;first identify&lt;/STRONG&gt; what constitutes to Independent parent task, and it's sub task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So taking this example&lt;/P&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.T1" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;task_id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;t&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;grp&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234R001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234S001&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;1234S001R002&lt;/TD&gt;
&lt;TD class="l data"&gt;1234&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;When you say&amp;nbsp;&lt;STRONG&gt;(note that main task id can be 4 or 8 or more digits)&amp;nbsp;,&amp;nbsp;&lt;/STRONG&gt;do you have a classification like the letter S denotes subtask or otherwise? I need your help in &lt;STRONG&gt;determining the classification&lt;/STRONG&gt;. That's the reason I presented Grouping GRP in the above. Also, when you say 4 or 8 digits. I see there digits(should mean numbers from 0-9) and characters.&amp;nbsp; Once we have a clear understanding, we can proceed with the logic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 15:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557158#M155279</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T15:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL counts by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557171#M155284</link>
      <description>&lt;P&gt;To make it simple, we can ignore the letter S, say main task id can be 4 or 8 digits, e.g. 1234 or 12345678. We only need to identify if the main id followed by R001 or R002 always 4 digits to indicate that the task has been re-done. e.g. 12345678R001 (same as previous 1234S001) meaning this is re-do task of 12345678. If a worker works on both main and re-do task, this only counts as 1 task done; if a worker only works on main or only works on re-do task (consider as independent task), this counts as 1 task done.&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;if a worker works on 12345678 and 12345678R001, this counts as 1 task done; if a worker works only on 12345678, this counts as 1 task done;&amp;nbsp;if a worker works only on 12345678R001 (without working on 12345678), this also counts as 1 task done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this is clear to you.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 15:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-counts-by-group/m-p/557171#M155284</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2019-05-08T15:48:29Z</dc:date>
    </item>
  </channel>
</rss>

