Table of Contents
The RANUNI function in SAS is a powerful tool that allows users to generate random numbers according to a specified distribution. This function can be used in a variety of applications, such as simulation studies, statistical analyses, and data manipulation. For example, it can be used to create a random sample of data for testing purposes, to generate random values for Monte Carlo simulations, or to assign random treatments to subjects in a clinical trial. Additionally, the RANUNI function can be customized to simulate various distributions, including uniform, normal, exponential, and Poisson. Its versatility and ease of use make it a valuable tool for researchers and data analysts in a wide range of fields.
Use the RANUNI Function in SAS (With Examples)
You can use the RANUNI function in SAS to generate values from the .
This function uses the following syntax:
RANUNI(seed)
where:
- seed: A non-negative integer to use as initial starting point for generating random values.
The following example shows how to use this function in practice.
Example 1: Use RANUNI Function to Generate One Random Value
We can use the following syntax with the RANUNI function to create a dataset that contains one random value between 0 and 1:
/*create dataset with one random value between 0 and 1*/
data my_data;
my_value=ranuni(0);
run;/*view dataset*/
proc printdata=my_data;

The RANUNI function generated the value 0.49370.
By default, the RANUNI function generates a random value between 0 and 1.
However, you can multiply the result of the RANUNI function by n to instead generate a random value between 1 and n.
For example, we can use the following syntax to generate a random value between 0 and 10:
/*create dataset with one random value between 0 and 10*/
data my_data;
my_value=ranuni(0)*10;
run;/*view dataset*/
proc printdata=my_data;
This time the RANUNI function generated the value 4.17403.
Example 2: Use RANUNI Function to Generate Several Random Values
We can use the following syntax with the RANUNI function to create a dataset that contains ten random values between 0 and 100:
/*create dataset with 10 random values between 0 and 100*/
data my_data;
do i=1to10by1;
my_value=ranuni(0)*100;
output;
end;
run;/*view dataset*/
proc printdata=my_data;

Notice that each of the values in the my_value column are between 0 and 100.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can the RANUNI function be used in SAS and what are some examples of its application?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-ranuni-function-be-used-in-sas-and-what-are-some-examples-of-its-application/
stats writer. "How can the RANUNI function be used in SAS and what are some examples of its application?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-ranuni-function-be-used-in-sas-and-what-are-some-examples-of-its-application/.
stats writer. "How can the RANUNI function be used in SAS and what are some examples of its application?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-ranuni-function-be-used-in-sas-and-what-are-some-examples-of-its-application/.
stats writer (2024) 'How can the RANUNI function be used in SAS and what are some examples of its application?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-ranuni-function-be-used-in-sas-and-what-are-some-examples-of-its-application/.
[1] stats writer, "How can the RANUNI function be used in SAS and what are some examples of its application?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can the RANUNI function be used in SAS and what are some examples of its application?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
