BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yuwentaiwan
Calcite | Level 5

Good afternoon fellow SAS users and the overall SAS community.

 

I want to random select then nember 1~100.

What is the different 

y1=1+99*ranuni(seed);

y2=100*ranuni(seed);

 

Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When you use

1+99*ranuni(seed)

Then the minimum value will be no less than 1.

When you use

100*ranuni(seed);

you may have a minimum like 100* 0.00000001.

 

I don't know what you mean by "select then nember 1~100" but if your goal is to generate random integers from 1 to 100 then use

 

rand('integer',100);

 

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

When you use

1+99*ranuni(seed)

Then the minimum value will be no less than 1.

When you use

100*ranuni(seed);

you may have a minimum like 100* 0.00000001.

 

I don't know what you mean by "select then nember 1~100" but if your goal is to generate random integers from 1 to 100 then use

 

rand('integer',100);

 

 

 

PeterClemmensen
Tourmaline | Level 20

Do you want to simulate a general random number or an integer?

yuwentaiwan
Calcite | Level 5

I want to  simulate a general random number,thanks.

andreas_lds
Jade | Level 19

Try

r = rand('Integer', 1, 100);
s_lassen
Meteorite | Level 14

I would use the more advanced random number generator, with the RAND function. RANUNI is relatively primitive - it generates a sequence of 2^32 integers (the seed value), which then repeats, and the integer values are all unique within the sequence. For your actual purpose it may be good enough, but make a habit of using the more advanced function.

 

There is no SEED parameter in RAND, but you can initialize the random number stream with a call to STREAMINIT, e.g.:

data want;
  call streaminit(253252); /* the seed initialization */
  n1=rand('UNIFORM',1,100); /* corresponds to 1+99*ranuni(seed), values between 1 and 100 */
  n2=rand('UNIFORM',100); /* corresponds to 100*ranuni(seed), values between 0 and 100 */
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 706 views
  • 0 likes
  • 5 in conversation