You can use SAS to generate random integers between 1–10 or in the range 1–100. This article shows how to generate random integers as easily as Excel does.
I was recently talking with some SAS customers and I was asked “Why can’t SAS create an easy way to generate random numbers? Excel has a simple way to generate random numbers between 1 and 100, and I use it all the time.”
The speaker was talking about generating random integers from a discrete uniform distribution, where the numbers range between a specified minimum and maximum value. I have previously written about how to generate random numbers in SAS, but the section about random integers is buried in the middle. So let’s simplify the process and see whether we can get SAS to generate random integers “as easily as Excel does.”
Builtin support for random integers
If you have access to SAS 9.4M5, you can generate random integers directly. The RAND function supports the “Integer” distribution and supports parameters that specify the min and max. To generate a random integer between 1 and 10 you can use the following statements:

A macro with a simple syntax
For older versions of SAS, you can define a macro. I looked up the Excel function that generates random integers. The syntax is RANDBETWEEN(min, max). For example, if you want a random integer between 1 and 10, the syntax is RANDBETWEEN(1, 10). For a random integer between 1 and 100, use RANDBETWEEN(1, 100).
The following SAS macro hides the complexity of the RAND function and creates a simple statement that that has the same functionality as the Excel function. It generates random uniform numbers in (0, 1), then transforms them to integers in [min, max]:

After you’ve defined the macro, you can just pretend that it is a function and use it in a DATA step. The following DATA step generates 100 random numbers between 1 and 10:

The adjacent table shows the first six random integers. Every time you run the program you will get a different sequence of random integers. Use the STREAMINIT subroutine if you want a reproducible stream of integers.
A SAS/IML function for random integers
The previous sections are for DATA step programmers. SAS/IML 14.2 also supports the “Integer” distribution. For earlier versions of SAS/IML, you can define a function that takes an additional argument and returns a vector of random integers:

The output shows that each integer 1 through 10 appeared approximately 1,000 times in the simulated data.
In summary, modern versions of SAS support the “Integer” distribution for generating random integers. For older versions of SAS, you can define a SAS macro that hides the complexity of the RAND function. The result is a syntax that is easy to use and duplicates the functionality of the Excel RANDBETWEEN function.