Lesson 34: Creating Randomness

Overview Section

In this lesson, we'll investigate ways to use some of the random number generators available in SAS:

  • to select a random sample of observations from a larger data set
  • to generate a scheme for assigning treatments to subjects in a randomized, controlled experiment
  • to generate (i.e., "simulate") numbers that follow some underlying probability distribution

The random generator functions used in the lesson include:

  • ranuni, which generates a number from a uniform (0, 1) distribution
  • rannor, which generates a number from a standard normal distribution
  • ranbin, which generates a number from a binomial (n, p) distribution
  • ranpoi, which generates a number from a Poisson distribution with mean m.

Other random functions available in SAS, but not illustrated in this lesson include rancau (a Cauchy distribution), rangam (a Gamma distribution), rantri (a triangular distribution), ranexp (an exponential distribution), and rantbl (a discrete distribution with user-specified probabilities).

In accomplishing the goals of the lesson, we'll primarily take advantage of the tools that are available to us in a SAS data step, such as do loops, if-then-else statements, retain, and output statements. By taking such an approach, we have not only the opportunity to review and put into practice these useful data step techniques but also the opportunity to better understand the processes of random sampling, random assignment, and simulation. In the case of random sampling, however, in addition to using the data step, we will also use the SURVEYSELECT procedure just so that you are aware of its basic functionality for your future use. Due to the time constraints of the course and the complexity of the PLAN procedure, we will not use it to accomplish any of our random assignments. You should be aware, however, of its existence should you want to explore it on your own in the future.

Objectives

Upon completion of this lesson, you should be able to:

  • use a seed in any of the random number generators that are available in SAS in order to generate a random number
  • use the ranuni function in a DATA step to select a random sample without replacement (either approximate-sized or exact-sized)
  • use the SURVEYSELECT procedure to select a random sample without replacement (either approximate-sized or exact-sized)
  • use the ranuni function and the POINT= option of the SET statement to randomly select an exact-sized random sample with a replacement
  • use the SURVEYSELECT procedure to select an exact-sized random sample with a replacement
  • use DATA steps to select a stratified random sample (of either equal- or unequal-sized groups)
  • use the SURVEYSELECT procedure to select a stratified random sample (of either equal- or unequal-sized groups)
  • use the ranuni function in a DATA step to create a random assignment plan for a completely randomized design with one factor
  • use the ranuni function in a DATA step to create a random assignment plan for a completely randomized design with two factors
  • use the ranuni function in a DATA step to create a random assignment plan for a randomized block design with one factor
  • use any of the random number generators that are available in SAS to simulate numbers that follow an underlying probability distribution