Good afternoon fellow SAS users and the overall SAS community.
I want to random select then nember 1~100.
What is the different
y1=1+99*ranuni(seed);
y2=100*ranuni(seed);
Thank you!!
When you use
1+99*ranuni(seed)
Then the minimum value will be no less than 1.
When you use
100*ranuni(seed);
you may have a minimum like 100* 0.00000001.
I don't know what you mean by "select then nember 1~100" but if your goal is to generate random integers from 1 to 100 then use
rand('integer',100);
When you use
1+99*ranuni(seed)
Then the minimum value will be no less than 1.
When you use
100*ranuni(seed);
you may have a minimum like 100* 0.00000001.
I don't know what you mean by "select then nember 1~100" but if your goal is to generate random integers from 1 to 100 then use
rand('integer',100);
Do you want to simulate a general random number or an integer?
I want to simulate a general random number,thanks.
Try
r = rand('Integer', 1, 100);
I would use the more advanced random number generator, with the RAND function. RANUNI is relatively primitive - it generates a sequence of 2^32 integers (the seed value), which then repeats, and the integer values are all unique within the sequence. For your actual purpose it may be good enough, but make a habit of using the more advanced function.
There is no SEED parameter in RAND, but you can initialize the random number stream with a call to STREAMINIT, e.g.:
data want;
call streaminit(253252); /* the seed initialization */
n1=rand('UNIFORM',1,100); /* corresponds to 1+99*ranuni(seed), values between 1 and 100 */
n2=rand('UNIFORM',100); /* corresponds to 100*ranuni(seed), values between 0 and 100 */
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.