BookmarkSubscribeRSS Feed
shursulei2
SAS Employee

Why the ranuni Function generate the random numbers  is not effect.Such as

data aa;
set sashelp.class;
y=ranuni(10);
run;

Why run the code twice ,but the result is sample.

I want to know how to use the sas to generate the random numbers 1 to 9.

as the programming of the python has random function to generate.

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @shursulei2 

 

In the code below , The RAND function returns a random uniformly distributed number in the interval (0,1). It is then multiplied by 9 auto output a random integer in the range 1 to 9. NB: The CEILZ function returns the smallest integer that is greater than or equal to the argument.

Is it what you are looking for?

 

y= ceilz(9*rand('uniform'));

Example:

data aa;
do i=1 to 100000000;
	y= ceilz(9*rand('uniform'));
	output;
end;
run;

proc freq;
	table y;
run;

Capture d’écran 2020-05-14 à 09.27.39.png

Best,

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1053 views
  • 2 likes
  • 3 in conversation