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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.