BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
7 REPLIES 7
data_null__
Jade | Level 19
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.
deleted_user
Not applicable
Thanks for the quick reply.

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

Thanks,
/Sukanya
Patrick
Opal | Level 21
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
data_null__
Jade | Level 19
> 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
deleted_user
Not applicable
Thanks All. This really helps. Now I understand how Seed value controls.
Sandhya
Fluorite | Level 6
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.
deleted_user
Not applicable
No, I just want to assign the random number for each observation randomly.

/Sukanya

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1935 views
  • 0 likes
  • 4 in conversation