Not applicable
Posts: 0

# How to assign random numbers 1, 2, 3 to subjects

Hello,

I want to assign random numbers 1, 2, 3 to subjects in a dataset. Not sure how to use RANUNI function. Please help.

Thanks,
/Sukanya
Posts: 3,852

## Re: How to assign random numbers 1, 2, 3 to subjects

I'm not sure I understand your question. If you want to assign dummy treatments to a list(data set) of subjects that is easily done using the RANTBL function.

[pre]
trt = rantbl(seed,1/3,1/3);
[/pre]

This assigns one of three values 1,2,3 with equal probability for each. I use this technique to create dummy treatments when working to data that is still blinded.

If you need something more complex like generating a plan that can be done too.
Not applicable
Posts: 0

## Re: How to assign random numbers 1, 2, 3 to subjects

Sorry I want to assign 0, 1, 2. How do I do that. How does Seed value controls ?

Thanks,
/Sukanya
Posts: 4,736

## Re: How to assign random numbers 1, 2, 3 to subjects

ranuni() gives you uniform distributed random numbers between 0 and 1.

The seed is the starting point from where you start picking the random numbers out of a very very long list of numbers.

If you use '0' as seed then the system time is used as seed and so the starting point is different for every execution of your code - resulting in an always different set of random numbers.

To assign random numbers between 0 and 2 use the following line in a data step:

RandomNumber=floor(ranuni()*3);

HTH
Patrick
Posts: 3,852

## Re: How to assign random numbers 1, 2, 3 to subjects

> Thanks for the quick reply.
>
> Sorry I want to assign 0, 1, 2. How do I do that.
Subtract 1.

> How does Seed value controls ?
SAS has online Help. It will explain the SEED and how to use it better than I can.

>
> Thanks,
> /Sukanya
Not applicable
Posts: 0

## Re: How to assign random numbers 1, 2, 3 to subjects

Thanks All. This really helps. Now I understand how Seed value controls.
Contributor
Posts: 57

## Re: How to assign random numbers 1, 2, 3 to subjects

Hi

Do you just want to assign random number or want to select samples from a big population.

If it is the second case use PROC SURVEYSELECT.

It is pretty straight forward.

Sandhya.
Not applicable
Posts: 0

## Re: How to assign random numbers 1, 2, 3 to subjects

No, I just want to assign the random number for each observation randomly.

/Sukanya
Discussion stats
• 7 replies
• 347 views
• 0 likes
• 4 in conversation