DATA Step, Macro, Functions and more

Random Number generation in SAS

Reply
Occasional Contributor
Posts: 15

Random Number generation in SAS

Hi Experts,

I am looking ways to pick a random number in milli seconds from a range of 2 minutes and allow the SAS process to sleep for that period:

I am currently using call sleep function, for SAS to sleep for a fixed amount of time.

Can any one please help!

Super Contributor
Posts: 578

Re: Random Number generation in SAS

how about

CALL SLEEP(rand(uniform)*120000, .001);

Occasional Contributor
Posts: 15

Re: Random Number generation in SAS

Thanks for your response:

Small change the works perfectly:

CALL SLEEP(rand("uniform")*120000, .001);

SAS Super FREQ
Posts: 3,752

Re: Random Number generation in SAS

To learn how to generate random numbers in SAS, see How to generate random numbers in SAS - The DO Loop

You must choose a minimum and maximum value for the sleep range.  You said "a range of 2 minutes," so I am going to assume that you mean that you want the sleep interval to be between 0 milliseconds and 120,000 milliseconds:

t = 120000 * rand("Uniform");  /* in range [0, 120,000] */

call sleep( t, 0.001);                 /* time in milliseconds */

An alternative way is to specify the sleep interval in seonds:

t1 = 120 * rand("Uniform");  /* in range [0, 120] */

call sleep( t, 1);                   /* time in seconds */

Occasional Contributor
Posts: 15

Re: Random Number generation in SAS

Thanks Rick!

Working perfectly.

Ask a Question
Discussion stats
  • 4 replies
  • 255 views
  • 1 like
  • 3 in conversation