turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Studio
- /
- Randomly generate names from a column (name) and g...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-05-2018 03:12 PM

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

Accepted Solutions

Solution

02-05-2018
05:44 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bobtalam

02-05-2018 05:13 PM

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.

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bobtalam

02-05-2018 03:18 PM - edited 02-05-2018 03:20 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-05-2018 03:21 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bobtalam

02-05-2018 03:44 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

02-05-2018 05:05 PM

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;

Solution

02-05-2018
05:44 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bobtalam

02-05-2018 05:13 PM

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.

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

02-05-2018 05:16 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to bobtalam

02-05-2018 05:48 PM

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;
```