<?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: split employees of a team into groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758147#M239362</link>
    <description>&lt;P&gt;You can assign systematically, but my approach is more complicated that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;'s very nice, compact approach.&amp;nbsp; See below for code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results are put into the log, and a SAS dataset is produced as well.&lt;/P&gt;
&lt;PRE&gt;NOTE:  Day 1  Employees needed today=5
       Employees for today: 1 through 5
NOTE:  Day 2  Employees needed today=5
       Employees for today: 6 through 10
NOTE:  Day 3  Employees needed today=5
       Employees for today: 11 through 15
NOTE:  Day 4  Employees needed today=5
       Employees for today: 16 through 20
NOTE:  Day 5  Employees needed today=6
       Employees for today: 21 through 26&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Nbr_of_Employees					=	26;
%LET	Days_This_Week						=	5;

DATA	Allocated_Employees;
	DROP	_:;
	_Employees_Per_Day						=	FLOOR(&amp;amp;Nbr_of_Employees / &amp;amp;Days_This_Week);
	_Unallocated_Employees					=	MOD(&amp;amp;Nbr_of_Employees, &amp;amp;Days_This_Week);
	ARRAY	Days		{*}						Day1 		- Day&amp;amp;Days_This_Week;
	ARRAY	Ranges_Low	{*}						Range_Low1	- Range_Low&amp;amp;Days_This_Week;
	ARRAY	Ranges_High	{*}						Range_High1	- Range_High&amp;amp;Days_This_Week;

	DO	_Day								=	&amp;amp;Days_This_Week	TO	1	BY	-1;
		Days{_Day}							=	_Employees_Per_Day;
		IF	_Unallocated_Employees			&amp;gt;	0	THEN
			DO;
				_Unallocated_Employees		+	-1;
				Days{_Day}					+	1;
			END;
	END;

	_Unallocated_Employees					=	&amp;amp;Nbr_of_Employees;

	DO	_Day								=	&amp;amp;Days_This_Week	TO	1	BY	-1;
		Ranges_High{_Day}					=	_Unallocated_Employees;
		_Unallocated_Employees				=	_Unallocated_Employees	-	Days{_Day};
		Ranges_Low{_Day}					=	_Unallocated_Employees	+	1;
	END;

	DO	_Day								=	1	TO	&amp;amp;Days_This_Week;
		PUTLOG	"NOTE:  Day "  _Day  " Employees needed today=" Days{_Day};
		PUTLOG	"NOTE-  Employees for today: "  Ranges_Low{_Day}  "through " Ranges_High{_Day};
	END;

	PUTLOG	"NOTE-  ";

	STOP;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 29 Jul 2021 16:24:04 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-07-29T16:24:04Z</dc:date>
    <item>
      <title>split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758120#M239350</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get a team with 26 employees (it could be change)&lt;/P&gt;
&lt;P&gt;I need to split the employees into group for each days of the Week. but sometimes the Week has 5 working days and sometimes 4&lt;/P&gt;
&lt;P&gt;in case of&amp;nbsp;5 working days, I need to get&amp;nbsp;5 values&amp;nbsp;5+5+5+5+6 =26&lt;/P&gt;
&lt;P&gt;in case of&amp;nbsp;4 working days, I need to get 4 values 6+6+7+7 = 26&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that, the aim is to identify employees with their number. I can do someting like this :"from employee n°1 to n°value1, from n°value1 ti n°value2...&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;Nasser&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 15:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758120#M239350</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-07-29T15:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758126#M239353</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to assign the employees &lt;EM&gt;randomly&lt;/EM&gt; to the five or four groups? If so, you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_surveyselect_syntax01.htm#statug.surveyselect.selectgroups" target="_blank" rel="noopener"&gt;GROUPS= option&lt;/A&gt; of PROC SURVEYSELECT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n_emp=26; /* number of employees */
%let n_wd=4;   /* number of working days */

/* Create test data for demonstration */

data have;
do empno=1 to &amp;amp;n_emp;
  output;
end;
run;

/* Assign employees to &amp;amp;n_wd groups */

proc surveyselect data=have groups=&amp;amp;n_wd
seed=2718 out=want;
run;

/* Check group sizes */

proc freq data=want;
tables GroupID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 15:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758126#M239353</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-29T15:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758131#M239355</link>
      <description>&lt;P&gt;Thanks !&lt;/P&gt;
&lt;P&gt;is it possible to get the n°group sorted ?&lt;/P&gt;
&lt;P&gt;I mean from employee 1 to employee&amp;nbsp;5 are grp 1, from employee&amp;nbsp;6 to employee&amp;nbsp;10 are grp 2...&lt;/P&gt;
&lt;P&gt;or is it random ?&lt;/P&gt;
&lt;P&gt;thanks,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 15:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758131#M239355</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-07-29T15:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758138#M239358</link>
      <description>&lt;P&gt;I haven't found an option in PROC SURVEYSELECT to obtain an output dataset sorted by &lt;FONT face="courier new,courier"&gt;GroupID&lt;/FONT&gt;, but of course you can apply PROC SORT to dataset WANT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want;
by GroupID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do you want to assign the employees &lt;EM&gt;systematically&lt;/EM&gt; (rather than randomly) to the groups?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758138#M239358</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-29T16:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758147#M239362</link>
      <description>&lt;P&gt;You can assign systematically, but my approach is more complicated that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;'s very nice, compact approach.&amp;nbsp; See below for code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results are put into the log, and a SAS dataset is produced as well.&lt;/P&gt;
&lt;PRE&gt;NOTE:  Day 1  Employees needed today=5
       Employees for today: 1 through 5
NOTE:  Day 2  Employees needed today=5
       Employees for today: 6 through 10
NOTE:  Day 3  Employees needed today=5
       Employees for today: 11 through 15
NOTE:  Day 4  Employees needed today=5
       Employees for today: 16 through 20
NOTE:  Day 5  Employees needed today=6
       Employees for today: 21 through 26&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Nbr_of_Employees					=	26;
%LET	Days_This_Week						=	5;

DATA	Allocated_Employees;
	DROP	_:;
	_Employees_Per_Day						=	FLOOR(&amp;amp;Nbr_of_Employees / &amp;amp;Days_This_Week);
	_Unallocated_Employees					=	MOD(&amp;amp;Nbr_of_Employees, &amp;amp;Days_This_Week);
	ARRAY	Days		{*}						Day1 		- Day&amp;amp;Days_This_Week;
	ARRAY	Ranges_Low	{*}						Range_Low1	- Range_Low&amp;amp;Days_This_Week;
	ARRAY	Ranges_High	{*}						Range_High1	- Range_High&amp;amp;Days_This_Week;

	DO	_Day								=	&amp;amp;Days_This_Week	TO	1	BY	-1;
		Days{_Day}							=	_Employees_Per_Day;
		IF	_Unallocated_Employees			&amp;gt;	0	THEN
			DO;
				_Unallocated_Employees		+	-1;
				Days{_Day}					+	1;
			END;
	END;

	_Unallocated_Employees					=	&amp;amp;Nbr_of_Employees;

	DO	_Day								=	&amp;amp;Days_This_Week	TO	1	BY	-1;
		Ranges_High{_Day}					=	_Unallocated_Employees;
		_Unallocated_Employees				=	_Unallocated_Employees	-	Days{_Day};
		Ranges_Low{_Day}					=	_Unallocated_Employees	+	1;
	END;

	DO	_Day								=	1	TO	&amp;amp;Days_This_Week;
		PUTLOG	"NOTE:  Day "  _Day  " Employees needed today=" Days{_Day};
		PUTLOG	"NOTE-  Employees for today: "  Ranges_Low{_Day}  "through " Ranges_High{_Day};
	END;

	PUTLOG	"NOTE-  ";

	STOP;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758147#M239362</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T16:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: split employees of a team into groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758586#M239553</link>
      <description>&lt;P&gt;Addendum: Formula for direct calculation of &lt;FONT face="courier new,courier"&gt;GroupID&lt;/FONT&gt; in a systematic group assignment (leading to the same group numbers and sizes as with PROC SURVEYSELECT, but without random selection).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let c=%sysfunc( ceil(&amp;amp;n_emp/&amp;amp;n_wd));
%let f=%sysfunc(floor(&amp;amp;n_emp/&amp;amp;n_wd));
%let r=%sysfunc(  mod(&amp;amp;n_emp,&amp;amp;n_wd));

data want;
set have nobs=n;
GroupID=ifn(_n_&amp;lt;=(&amp;amp;n_wd-&amp;amp;r)*&amp;amp;f, ceil(_n_/&amp;amp;f), &amp;amp;n_wd-floor((n-_n_)/&amp;amp;c));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Jul 2021 10:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-employees-of-a-team-into-groups/m-p/758586#M239553</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-31T10:51:48Z</dc:date>
    </item>
  </channel>
</rss>

