BookmarkSubscribeRSS Feed
desireatem
Pyrite | Level 9

Hello Ladies and Gentlemen,

I am trying to output a random number within a proc iml statement.

For example if i do: A=RANUNI(-1); any time it give a different random number between 0 and 1.

Now I have my interval (Bi, Bi+1) and I want a random number between this interval. Just like RANUNI(-1), I want this interval to change anytime I run it and to vary as I vary my interval

4 REPLIES 4
Rick_SAS
SAS Super FREQ

See the article How to generate random numbers in SAS - The DO Loop which shows how to use the RANDGEN routine to generate random numbers.  If u is in the inerval [0,1] then Bi+u is in the interval you want.   You can use CALL RANDSEED(0) if you want the random number stream to be different each time you run the program.  Remember also that if you are going to need thousands of random numbers to vectorize the program by allocating an array and filling it: Efficient Sampling - The DO Loop

desireatem
Pyrite | Level 9

My  interval varies and it is  like (0.93, 1.41) and I want a random a within the the interval. THe other interval is (0.67,0.83)

1zmm
Quartz | Level 8

If the uniform random number you generate equals RN, the random value within a specific interval from LOW to HIGH equals:

      Random value = LOW + RN*(HIGH - LOW).

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1055 views
  • 0 likes
  • 3 in conversation