BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bobtalam
Calcite | Level 5

I'm using sas studio how do I generate random names from a group of 200 obs and group the names in groups of 4. Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You want an N=4 and REPS=50. Note that you've specified SRS which is Simple Random Sample which means names can be repeated.

 

delete_surveyselect.JPG

 


@bobtalam wrote:

Thanks for you response. I do have this as my code, but I don't know where to put the specification to group them into group of 4. 

proc surveyselect data=work.import
method=srs n=38
out=work.samplesrs;
run;

 


 

View solution in original post

7 REPLIES 7
HB
Barite | Level 11 HB
Barite | Level 11

Are you asking how you would assign each of 200 observations randomly to one of four groups?

 

If you are, PROC SURVEYSELECT might be where you want to go.

bobtalam
Calcite | Level 5

I wanted to randomly assign them into 50 groups of 4 participants in each.

Reeza
Super User

PROC SURVEYSELECT is the way to go then. The documentation has examples, if you have issues with the implementation post your code, referencing the SASHELP.CLASS data set or including sample data.

 

The 'manual' way would be to create a random number, sort by random number, Group each 4 together using the MOD() function.

 


@bobtalam wrote:

I wanted to randomly assign them into 50 groups of 4 participants in each.


 

bobtalam
Calcite | Level 5

Thanks for you response. I do have this as my code, but I don't know where to put the specification to group them into group of 4. 

proc surveyselect data=work.import
method=srs n=38
out=work.samplesrs;
run;

 

Reeza
Super User

You want an N=4 and REPS=50. Note that you've specified SRS which is Simple Random Sample which means names can be repeated.

 

delete_surveyselect.JPG

 


@bobtalam wrote:

Thanks for you response. I do have this as my code, but I don't know where to put the specification to group them into group of 4. 

proc surveyselect data=work.import
method=srs n=38
out=work.samplesrs;
run;

 


 

bobtalam
Calcite | Level 5

Is there a way I can set it not to repeat names?

Reeza
Super User

I would think so, but I can't seem to figure it out. I'm 99% sure there's a way though so I'll move it to the stats forum.

 

Here's the random variable method:

 

data _random;
set sashelp.class;
rand = rand('normal', 0, 25);
run;

proc sort data=_Random;
by rand;run;

data groups;
set _random;
if _n_=1 then group=0;

if mod(_n_, 2) = 1 then group+1;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2011 views
  • 1 like
  • 3 in conversation