<?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: Forming new group based on the sub group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809134#M319052</link>
    <description>&lt;P&gt;I'm not sure I grasp the method of creating this new group variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first 3 rows have new_group=1, based on what logic? Please explain.&lt;/P&gt;
&lt;P&gt;The next 4 rows have new_group=2, based on what logic? Please explain.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 17:23:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-04-21T17:23:11Z</dc:date>
    <item>
      <title>Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809120#M319049</link>
      <description>&lt;P&gt;Hi All&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id $ group (start_time end_time) (:datetime19.);&lt;BR /&gt;format start_time end_time e8601dt19.;&lt;BR /&gt;datalines;&lt;BR /&gt;1-10 1 27FEB22:12:32:00 27FEB22:13:04:00&lt;BR /&gt;1-9 1 27FEB22:12:32:00 27FEB22:13:04:00&lt;BR /&gt;2-15 1 27FEB22:12:33:00 27FEB22:13:12:00&lt;BR /&gt;1-4 2 27FEB22:10:00:00 27FEB22:10:51:00&lt;BR /&gt;1-5 2 27FEB22:10:00:00 27FEB22:10:51:00&lt;BR /&gt;1-5 3 27FEB22:10:27:00 27FEB22:11:39:00&lt;BR /&gt;1-6 3 27FEB22:10:27:00 27FEB22:11:39:00&lt;BR /&gt;1-6 4 25FEB22:09:18:00 25FEB22:09:33:00&lt;BR /&gt;1-7 4 25FEB22:09:18:00 25FEB22:09:33:00&lt;BR /&gt;1-7 5 27FEB22:11:33:00 27FEB22:12:39:00&lt;BR /&gt;1-8 5 27FEB22:11:33:00 27FEB22:12:39:00&lt;BR /&gt;1-8 6 27FEB22:11:34:00 27FEB22:12:39:00&lt;BR /&gt;1-9 6 27FEB22:11:34:00 27FEB22:12:39:00&lt;BR /&gt;103-21 7 05APR22:12:26:00 05APR22:13:02:00&lt;BR /&gt;103-22 7 05APR22:12:26:00 05APR22:13:02:00&lt;BR /&gt;102-58 8 05APR22:12:43:00 05APR22:13:06:00&lt;BR /&gt;103-22 8 05APR22:12:43:00 05APR22:13:06:00&lt;BR /&gt;103-17 9 05APR22:11:26:00 05APR22:12:34:00&lt;BR /&gt;103-19 9 05APR22:11:26:00 05APR22:12:34:00&lt;BR /&gt;103-19 10 05APR22:11:27:00 05APR22:12:52:00&lt;BR /&gt;103-21 10 05APR22:11:27:00 05APR22:12:52:00&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Expected Output :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sastech_0-1650560080888.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70685iD11CEF554C729907/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sastech_0-1650560080888.png" alt="Sastech_0-1650560080888.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. We are forming the variable new_group based on a time span covered by all members of a group.&lt;BR /&gt;(time span is defined as the earliest start and latest end of all the observations in a group)&lt;BR /&gt;2. all members of a group will be assigned to the same new_group.&lt;BR /&gt;3. The first group will be assigned newgroup=1.&lt;BR /&gt;4. If the earliest start_time or last end_time of a group falls in between already formed newgroup's earliest start_time and last end_time and also id's of the group also match newgroup then it should be included with the newgroup. Otherwise, it should create a new newsgroup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;BR /&gt;1.Eventhough group 2 and 3 have same ids , they should not come under same new_group because both groups are having different time and they did not intersect/overlap.&lt;BR /&gt;2. Single id value should not come under multiple new_groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 16:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809120#M319049</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-21T16:55:49Z</dc:date>
    </item>
    <item>
      <title>Group based on scenario</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809109#M319087</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;The data needs to be grouped based on conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input id $ group (start_time end_time) (:datetime19.);&lt;BR /&gt;format start_time end_time e8601dt19.;&lt;BR /&gt;datalines;&lt;BR /&gt;1-10 1 27FEB22:12:32:00 27FEB22:13:04:00&lt;BR /&gt;1-9 1 27FEB22:12:32:00 27FEB22:13:04:00&lt;BR /&gt;2-15 1 27FEB22:12:33:00 27FEB22:13:12:00&lt;BR /&gt;1-4 2 27FEB22:10:00:00 27FEB22:10:51:00&lt;BR /&gt;1-5 2 27FEB22:10:00:00 27FEB22:10:51:00&lt;BR /&gt;1-5 3 27FEB22:10:27:00 27FEB22:11:39:00&lt;BR /&gt;1-6 3 27FEB22:10:27:00 27FEB22:11:39:00&lt;BR /&gt;1-6 4 25FEB22:09:18:00 25FEB22:09:33:00&lt;BR /&gt;1-7 4 25FEB22:09:18:00 25FEB22:09:33:00&lt;BR /&gt;1-7 5 27FEB22:11:33:00 27FEB22:12:39:00&lt;BR /&gt;1-8 5 27FEB22:11:33:00 27FEB22:12:39:00&lt;BR /&gt;1-8 6 27FEB22:11:34:00 27FEB22:12:39:00&lt;BR /&gt;1-9 6 27FEB22:11:34:00 27FEB22:12:39:00&lt;BR /&gt;103-21 7 05APR22:12:26:00 05APR22:13:02:00&lt;BR /&gt;103-22 7 05APR22:12:26:00 05APR22:13:02:00&lt;BR /&gt;102-58 8 05APR22:12:43:00 05APR22:13:06:00&lt;BR /&gt;103-22 8 05APR22:12:43:00 05APR22:13:06:00&lt;BR /&gt;103-17 9 05APR22:11:26:00 05APR22:12:34:00&lt;BR /&gt;103-19 9 05APR22:11:26:00 05APR22:12:34:00&lt;BR /&gt;103-19 10 05APR22:11:27:00 05APR22:12:52:00&lt;BR /&gt;103-21 10 05APR22:11:27:00 05APR22:12:52:00&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Expected Output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASTECH1_0-1650559537876.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70683iC41FE2DB8B617B03/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASTECH1_0-1650559537876.png" alt="SASTECH1_0-1650559537876.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Grouping needs to be done based on below conditions.&lt;/P&gt;&lt;P&gt;1. We are forming the variable new_group based on a time span covered by all members of a group.&lt;BR /&gt;(time span is defined as the earliest start and latest end of all the observations in a group)&lt;BR /&gt;2. all members of a group will be assigned to the same new_group.&lt;BR /&gt;3. The first group will be assigned newgroup=1.&lt;BR /&gt;4. If the earliest start_time or last end_time of a group falls in between already formed newgroup's earliest start_time and last end_time and also id's of the group also match newgroup then it should be included with the newgroup. Otherwise, it should create a new newsgroup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;BR /&gt;1.Eventhough group 2 and 3 have same ids , they should not come under same new_group because both groups are having different time and they did not intersect/overlap.&lt;BR /&gt;2. Single id value should not come under multiple new_groups.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help on this.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 16:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809109#M319087</guid>
      <dc:creator>SASTECH1</dc:creator>
      <dc:date>2022-04-21T16:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809134#M319052</link>
      <description>&lt;P&gt;I'm not sure I grasp the method of creating this new group variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first 3 rows have new_group=1, based on what logic? Please explain.&lt;/P&gt;
&lt;P&gt;The next 4 rows have new_group=2, based on what logic? Please explain.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809134#M319052</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-21T17:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809141#M319058</link>
      <description>The first 3 rows have new_group=1 because group 1 of ids does not match with the any other group of ids so its starts with new_group 1&lt;BR /&gt;&lt;BR /&gt;The next 4 rows have new_group=2 beacuse from group 2 and 3 the id 1-5 is common in group 2 and 3 so its coming under the new_group 2.&lt;BR /&gt;From group 3 and 4 the id 1-6 is common in the both the group but time span is different so its not joining into same new_group 2 and its new_group 3&lt;BR /&gt;From group 4 and 5 the id 1-7 is common in the both the group but time span is different so its not joining into same new_group 3 and its new_group 4&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809141#M319058</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-21T17:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809143#M319060</link>
      <description>&lt;P&gt;So we only have to look at the next group, we would never have to look at the group that is five groups away?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 17:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809143#M319060</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-21T17:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809144#M319061</link>
      <description>we have to look next common ids from one group to other group. if we see group 7 and the id 103 -21 is match with group 10 and coming under the same newgroup 5</description>
      <pubDate>Thu, 21 Apr 2022 18:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809144#M319061</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-21T18:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Group based on scenario</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809207#M319088</link>
      <description>&lt;P&gt;Why is GROUP 5 not in NEWGROUP 2 since it overlaps?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 06:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809207#M319088</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-04-22T06:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Group based on scenario</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809215#M319089</link>
      <description>&lt;P&gt;Please don't double post questions.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 07:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809215#M319089</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-22T07:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Group based on scenario</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809235#M319091</link>
      <description>&lt;P&gt;The ids in group 5 (1-7 and 1-8) are not in Newgroup -2. So only it is not in newgroup2 though time window overlap.&amp;nbsp;&lt;/P&gt;&lt;P&gt;New groups should be assigned based on both conditions checking ids present in it and also time overlap.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 08:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809235#M319091</guid>
      <dc:creator>SASTECH1</dc:creator>
      <dc:date>2022-04-22T08:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809263#M319104</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&lt;BR /&gt;except timespan everything is working as expected&lt;BR /&gt;how to alter the the code for across the days.&lt;BR /&gt;&lt;BR /&gt;data out;&lt;BR /&gt;if 0 then set innerjoin_table_new1_t;&lt;BR /&gt;retain newgroup max_newgroup;&lt;BR /&gt;if _n_ = 1&lt;BR /&gt;then do;&lt;BR /&gt;declare hash new ();&lt;BR /&gt;new.definekey("gtmds_uid");&lt;BR /&gt;new.definedata("newgroup");&lt;BR /&gt;new.definedone();&lt;BR /&gt;max_newgroup = 0;&lt;BR /&gt;end;&lt;BR /&gt;ng = 0;&lt;BR /&gt;do until (last.group);&lt;BR /&gt;set innerjoin_table_new1_t;&lt;BR /&gt;by group;&lt;BR /&gt;if new.find() = 0 then ng = newgroup;&lt;BR /&gt;end;&lt;BR /&gt;if not ng&lt;BR /&gt;then do;&lt;BR /&gt;max_newgroup + 1;&lt;BR /&gt;ng = max_newgroup;&lt;BR /&gt;end;&lt;BR /&gt;newgroup = ng;&lt;BR /&gt;do until (last.group);&lt;BR /&gt;set innerjoin_table_new1_t;&lt;BR /&gt;by group;&lt;BR /&gt;if new.check() ne 0&lt;BR /&gt;then rc = new.add();&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop max_newgroup rc ng;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Apr 2022 11:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809263#M319104</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-22T11:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809273#M319113</link>
      <description>&lt;P&gt;Your code uses gtmds_uid as key of the hash, but this variable does not exist in the example dataset you posted.&lt;/P&gt;
&lt;P&gt;Does id play any role in the building of new groups, or is it only the date that defines a group?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 12:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809273#M319113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-22T12:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809275#M319115</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;BR /&gt;Updated the code shared below.&lt;BR /&gt;1.Eventhough group 2 and 3 have same ids , they should not come under same new_group because both groups are having different time and they did not intersect/overlap.&lt;BR /&gt;2. Single id value should not come under multiple new_groups.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data out;&lt;BR /&gt;if 0 then set have;&lt;BR /&gt;retain newgroup max_newgroup;&lt;BR /&gt;if _n_ = 1&lt;BR /&gt;then do;&lt;BR /&gt;declare hash new ();&lt;BR /&gt;new.definekey("id");&lt;BR /&gt;new.definedata("newgroup");&lt;BR /&gt;new.definedone();&lt;BR /&gt;max_newgroup = 0;&lt;BR /&gt;end;&lt;BR /&gt;ng = 0;&lt;BR /&gt;do until (last.group);&lt;BR /&gt;set innerjoin_table_new1_t;&lt;BR /&gt;by group;&lt;BR /&gt;if new.find() = 0 then ng = newgroup;&lt;BR /&gt;end;&lt;BR /&gt;if not ng&lt;BR /&gt;then do;&lt;BR /&gt;max_newgroup + 1;&lt;BR /&gt;ng = max_newgroup;&lt;BR /&gt;end;&lt;BR /&gt;newgroup = ng;&lt;BR /&gt;do until (last.group);&lt;BR /&gt;set innerjoin_table_new1_t;&lt;BR /&gt;by group;&lt;BR /&gt;if new.check() ne 0&lt;BR /&gt;then rc = new.add();&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop max_newgroup rc ng;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 22 Apr 2022 12:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809275#M319115</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-22T12:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809276#M319116</link>
      <description>&lt;P&gt;You perfectly contradict yourself. In 1) you say that same id's should belong to different newgroups (under certain conditions), but in 2) you say that a single id should always be in the same newgroup.&lt;/P&gt;
&lt;P&gt;Please make up your mind.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 12:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809276#M319116</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-22T12:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809458#M319226</link>
      <description>&lt;P&gt;Hi&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank"&gt;@Kurt_Bremser&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1-6 and 1- 7 (Group 4) need to be set to be with a separate newgroup as this window &lt;STRONG&gt;25-02-2022 09:18:00 to 25-02-2022 09:33:00&lt;/STRONG&gt; happens at a separate time window which is not overlapping with any other newgroups time window.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: 1. If the time window of the group intersects/overlaps with newgroup and ids match, then the group will be added with the same newgroup. 2. If ids are not matching or time windows are not overlapping, then that group will be generated with newgroup number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sastech_0-1650737806332.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70759i4122AB92934D891A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sastech_0-1650737806332.png" alt="Sastech_0-1650737806332.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 18:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809458#M319226</guid>
      <dc:creator>Sastech</dc:creator>
      <dc:date>2022-04-23T18:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Forming new group based on the sub group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809779#M319339</link>
      <description>&lt;P&gt;I'm not sure about the interaction between IDs and formation of new groups because some of the info shared in this post seems inconsistent or contradictory. However, if the current group's range of time overlaps the new group's range of time, you can get the desired outcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* determine each group's min start and max end;
proc summary data=have nway;
class group;
output out=grp_range (drop=_:) min(start_time)=min_grp_start max(end_time)=max_grp_end;
run;

* determine new groups based only on overlaps of time;
data new_groups;
set grp_range;
retain new_group 0 min_new_grp_start max_new_grp_end;
format min_new_grp_start max_new_grp_end e8601dt19.;

* test if current group overlaps the current new_group;
* if not, then create a new group and reset the new group dates;
if not (min_grp_start &amp;lt;= max_new_grp_end and max_grp_end &amp;gt;= min_new_grp_start) then do;
   new_group + 1;
   min_new_grp_start = min_grp_start;
   max_new_grp_end = max_grp_end;
end;

* dynamically calc new group min and max;
min_new_grp_start = min(min_new_grp_start, min_grp_start);
max_new_grp_end = max(max_new_grp_end, max_grp_end);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, a much larger sample is needed to fully vet this logic.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 21:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Forming-new-group-based-on-the-sub-group/m-p/809779#M319339</guid>
      <dc:creator>average_joe</dc:creator>
      <dc:date>2022-04-25T21:22:40Z</dc:date>
    </item>
  </channel>
</rss>

