tweaked2005
Technical User
I'm stumped. I need to create a SAS program that randomly matches names for dinner. There are a few criteria to consider:
There are 3 categories of folks, those that can go to dinner in groups of 3 only, can go to dinner in groups of 2 only, or are indifferent.
The program needs to match folks up for dinner randomly, and then record (perhaps in a new variable) that those folks have gone to dinner. This is so they will not be matched again in the near future.
I've listed the code I have completed below. There are some obvious problems - someone in the "indifferent" category could very well be matched with someone else in the "indifferent" category - but as it stands that is not happening. For now I'm trying to chip away at the different pieces of this program. Any help would be greatly apreciated.
The dataset out.participants contains the following variables:
firstName, lastName, group (the category each person is in), center, division
There are 3 categories of folks, those that can go to dinner in groups of 3 only, can go to dinner in groups of 2 only, or are indifferent.
The program needs to match folks up for dinner randomly, and then record (perhaps in a new variable) that those folks have gone to dinner. This is so they will not be matched again in the near future.
I've listed the code I have completed below. There are some obvious problems - someone in the "indifferent" category could very well be matched with someone else in the "indifferent" category - but as it stands that is not happening. For now I'm trying to chip away at the different pieces of this program. Any help would be greatly apreciated.
The dataset out.participants contains the following variables:
firstName, lastName, group (the category each person is in), center, division
Code:
libname out 'c:\';
data group1; set out.participants;
if group=1;
rannum=ranuni(0);
data group2; set out.participants;
if group=2;
rannum=ranuni(0);
data group3; set out.participants;
if group=3;
rannum=ranuni(0);
proc sort data=group1; by rannum;
proc sort data=group2; by rannum;
proc sort data=group3; by rannum;
data group1 (rename=(
firstName=fname1
lastName=lname1
group=g1
center=c1
division=d1)
); set group1;
n=_n_;
data group2 (rename=
(
firstName=fname2
lastName=lname2
group=g2
center=c2
division=d2
)
); set group2;
n=_n_;
data group3 (rename=(
firstName=fname3
lastName=lname3
group=g3
center=c3
division=d3)
); set group3;
n=_n_;
proc sort data=group1; by n;
proc sort data=group2; by n;
proc sort data=group3; by n;
run;
data match1; merge group1 group2;
by n;
run;
proc print; run;