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,

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 966 views
  • 2 likes
  • 3 in conversation