BookmarkSubscribeRSS Feed
aruku
Calcite | Level 5

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!

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

how about

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

aruku
Calcite | Level 5

Thanks for your response:

Small change the works perfectly:

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

Rick_SAS
SAS Super FREQ

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 */

aruku
Calcite | Level 5

Thanks Rick!

Working perfectly.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 987 views
  • 1 like
  • 3 in conversation