SAS Procedures

Help using Base SAS procedures
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2889 views
  • 0 likes
  • 4 in conversation