<?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 create subgroup number by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-subgroup-number-by-group/m-p/765800#M242592</link>
    <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;I have a team with 29 employees (it could change) &amp;nbsp;in 5 (it could change) &amp;nbsp;groups .see table HAVE. some groups have 5 employees, and some groups have 6 employees&lt;/P&gt;
&lt;P&gt;What I would like to obtain : divide each group into two subgroup with equal number employees whenever it is possible&lt;/P&gt;
&lt;P&gt;for groups with 5 employees, get a subgroup number that is 1,1,1,2,2&lt;/P&gt;
&lt;P&gt;for groups with 6 employees get a subgroup number that is 1,1,1,2,2,2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks in advance for your help&lt;/P&gt;
&lt;PRE&gt;Data have  ;
infile datalines ;
input name $ group $1. subgroup $1. ;
datalines ;
Andrew 1
Barbara 1
Boris 1
Bryan 1
Carla 1
Christophe 2
David 2
Emma 2
Eric 2
Fred 2
Henry 2
Hugo 3
Jamal 3
Jeff 3
Kylian 3
Lionel 3
Maelle 3
Martin 4
Michael 4
Nadia 4
Nasser 4
Paul 4
Robert 4
Sacha 5
Salah 5
Samuel 5
Sophie 5
Stefan 5
Zakia 5
;
run ;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Sep 2021 07:39:25 GMT</pubDate>
    <dc:creator>Nasser_DRMCP</dc:creator>
    <dc:date>2021-09-03T07:39:25Z</dc:date>
    <item>
      <title>create subgroup number by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-subgroup-number-by-group/m-p/765800#M242592</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;I have a team with 29 employees (it could change) &amp;nbsp;in 5 (it could change) &amp;nbsp;groups .see table HAVE. some groups have 5 employees, and some groups have 6 employees&lt;/P&gt;
&lt;P&gt;What I would like to obtain : divide each group into two subgroup with equal number employees whenever it is possible&lt;/P&gt;
&lt;P&gt;for groups with 5 employees, get a subgroup number that is 1,1,1,2,2&lt;/P&gt;
&lt;P&gt;for groups with 6 employees get a subgroup number that is 1,1,1,2,2,2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks in advance for your help&lt;/P&gt;
&lt;PRE&gt;Data have  ;
infile datalines ;
input name $ group $1. subgroup $1. ;
datalines ;
Andrew 1
Barbara 1
Boris 1
Bryan 1
Carla 1
Christophe 2
David 2
Emma 2
Eric 2
Fred 2
Henry 2
Hugo 3
Jamal 3
Jeff 3
Kylian 3
Lionel 3
Maelle 3
Martin 4
Michael 4
Nadia 4
Nasser 4
Paul 4
Robert 4
Sacha 5
Salah 5
Samuel 5
Sophie 5
Stefan 5
Zakia 5
;
run ;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 07:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-subgroup-number-by-group/m-p/765800#M242592</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-09-03T07:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: create subgroup number by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-subgroup-number-by-group/m-p/765808#M242599</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;I have a team with 29 employees (it could change) &amp;nbsp;in 5 (it could change) &amp;nbsp;groups .see table HAVE. some groups have 5 employees, and some groups have 6 employees&lt;/P&gt;
&lt;P&gt;What I would like to obtain : divide each group into two subgroup with equal number employees whenever it is possible&lt;/P&gt;
&lt;P&gt;for groups with 5 employees, get a subgroup number that is 1,1,1,2,2&lt;/P&gt;
&lt;P&gt;for groups with 6 employees get a subgroup number that is 1,1,1,2,2,2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks in advance for your help&lt;/P&gt;
&lt;PRE&gt;Data have  ;
infile datalines ;
input name $ group $1. subgroup $1. ;
datalines ;
Andrew 1
Barbara 1
Boris 1
Bryan 1
Carla 1
Christophe 2
David 2
Emma 2
Eric 2
Fred 2
Henry 2
Hugo 3
Jamal 3
Jeff 3
Kylian 3
Lionel 3
Maelle 3
Martin 4
Michael 4
Nadia 4
Nasser 4
Paul 4
Robert 4
Sacha 5
Salah 5
Samuel 5
Sophie 5
Stefan 5
Zakia 5
;
run ;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This creates a random subgroup:&lt;/P&gt;
&lt;PRE&gt;Data have  ;
infile datalines ;
input name $ group $1. ;
datalines ;
Andrew 1
Barbara 1
Boris 1
Bryan 1
Carla 1
Christophe 2
David 2
Emma 2
Eric 2
Fred 2
Henry 2
Hugo 3
Jamal 3
Jeff 3
Kylian 3
Lionel 3
Maelle 3
Martin 4
Michael 4
Nadia 4
Nasser 4
Paul 4
Robert 4
Sacha 5
Salah 5
Samuel 5
Sophie 5
Stefan 5
Zakia 5
;

proc sort data=have;
   by group;
run;

proc surveyselect data=have 
                 out=want(rename=(groupid=subgroup))
    groups=2;
    strata group;
run;&lt;/PRE&gt;
&lt;P&gt;The proc sort is needed if your data is not sorted by the group to allow use of group as the Strata variable.&lt;/P&gt;
&lt;P&gt;The Groups= option randomly assigns each record to one of the number indicated for each strata. The rename on the out= option is to change the name of the automatic variable Groupid created by the Groups= option. Subgroup will be numeric in the output. If you need a character variable then use the Want data set as the input to a data step to create the desired character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: Group is an option name in multiple SAS procedures. You may want to use a different variable name then group to avoid possible confusion between your variable and the option.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 08:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-subgroup-number-by-group/m-p/765808#M242599</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-03T08:15:09Z</dc:date>
    </item>
  </channel>
</rss>

