hello,
I get a team with 26 employees (it could be change)
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
in case of 5 working days, I need to get 5 values 5+5+5+5+6 =26
in case of 4 working days, I need to get 4 values 6+6+7+7 = 26
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...
thanks in advance
Nasser
Hello @Nasser_DRMCP,
Do you want to assign the employees randomly to the five or four groups? If so, you can use the GROUPS= option of PROC SURVEYSELECT:
%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 &n_emp;
output;
end;
run;
/* Assign employees to &n_wd groups */
proc surveyselect data=have groups=&n_wd
seed=2718 out=want;
run;
/* Check group sizes */
proc freq data=want;
tables GroupID;
run;
Hello @Nasser_DRMCP,
Do you want to assign the employees randomly to the five or four groups? If so, you can use the GROUPS= option of PROC SURVEYSELECT:
%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 &n_emp;
output;
end;
run;
/* Assign employees to &n_wd groups */
proc surveyselect data=have groups=&n_wd
seed=2718 out=want;
run;
/* Check group sizes */
proc freq data=want;
tables GroupID;
run;
Thanks !
is it possible to get the n°group sorted ?
I mean from employee 1 to employee 5 are grp 1, from employee 6 to employee 10 are grp 2...
or is it random ?
thanks,
I haven't found an option in PROC SURVEYSELECT to obtain an output dataset sorted by GroupID, but of course you can apply PROC SORT to dataset WANT:
proc sort data=want;
by GroupID;
run;
Or do you want to assign the employees systematically (rather than randomly) to the groups?
Addendum: Formula for direct calculation of GroupID in a systematic group assignment (leading to the same group numbers and sizes as with PROC SURVEYSELECT, but without random selection).
%let c=%sysfunc( ceil(&n_emp/&n_wd));
%let f=%sysfunc(floor(&n_emp/&n_wd));
%let r=%sysfunc( mod(&n_emp,&n_wd));
data want;
set have nobs=n;
GroupID=ifn(_n_<=(&n_wd-&r)*&f, ceil(_n_/&f), &n_wd-floor((n-_n_)/&c));
run;
You can assign systematically, but my approach is more complicated that @FreelanceReinh's very nice, compact approach. See below for code.
Results are put into the log, and a SAS dataset is produced as well.
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
Jim
%LET Nbr_of_Employees = 26;
%LET Days_This_Week = 5;
DATA Allocated_Employees;
DROP _:;
_Employees_Per_Day = FLOOR(&Nbr_of_Employees / &Days_This_Week);
_Unallocated_Employees = MOD(&Nbr_of_Employees, &Days_This_Week);
ARRAY Days {*} Day1 - Day&Days_This_Week;
ARRAY Ranges_Low {*} Range_Low1 - Range_Low&Days_This_Week;
ARRAY Ranges_High {*} Range_High1 - Range_High&Days_This_Week;
DO _Day = &Days_This_Week TO 1 BY -1;
Days{_Day} = _Employees_Per_Day;
IF _Unallocated_Employees > 0 THEN
DO;
_Unallocated_Employees + -1;
Days{_Day} + 1;
END;
END;
_Unallocated_Employees = &Nbr_of_Employees;
DO _Day = &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 &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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.