BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

I have been using the rannor function as:

 

eps1=rannor(1)*sqrt(feps1);

eps2=rannor(2)*sqrt(feps2);

 

 

I have looked at examples (e.g., Rand (Normal)),  but it is not clear to me how to code my function.

My question is how to properly code my sqrt(feps1) with the rand function for a normal distribution?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@jacksonan123 wrote:
I received the following reply:

Is your concern about controlling the seed of the Rand('Normal') ? If not
the equivalent code would be :

eps1 = rand('Normal') * sqrt(feps1);

Which is the same as yours (without the mean), but the issue for me which I
failed to initially clearly state would be to control the seed as
indicated in the response.

If you need to repeat the stream of random numbers you would use Call Streaminit(seedvalue) before calling any of the RAND functions. However there is only one stream sequence of random numbers created.

View solution in original post

8 REPLIES 8
JosvanderVelden
SAS Super FREQ
Have a look at the information here "https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lefunctionsref&docsetT..." and here "https://newonlinecourses.science.psu.edu/stat482/node/33/". I believe you'll find the examples you request there.
jacksonan123
Lapis Lazuli | Level 10
Yes that does give an explicit example and also addresses the issue of the
seed which I failed to mention in the original post.
ballardw
Super User

@jacksonan123 wrote:

I have been using the rannor function as:

 

eps1=rannor(1)*sqrt(feps1);

eps2=rannor(2)*sqrt(feps2);

 

 

I have looked at examples (e.g., Rand (Normal)),  but it is not clear to me how to code my function.

My question is how to properly code my sqrt(feps1) with the rand function for a normal distribution?

 


Is your concern about controlling the seed of the Rand('Normal') ? If not the equivalent code would be :

 

eps1 = rand('Normal') * sqrt(feps1);

 

Or else you example code is misleading as the sqrt(feps1) has no impact on selecting the random value. Or are you trying to use the sqrt value as a parameter of the normal distribution?

jacksonan123
Lapis Lazuli | Level 10
My concern is to control the seed. The sqrt value is a value determined
from a separate analysis and I only want to add random error and it is not a
parameter of the normal distribution.
FreelanceReinh
Jade | Level 19
@ballardw wrote:



(...) However there is only one stream sequence of random numbers created.


Which is actually the same as with your RANNOR seed values: Specifying different seeds in the same DATA step (like 1 and 2 in your example) is pointless because only the first value will be used (as you can check easily by changing the second seed to the first).

FreelanceReinh
Jade | Level 19

Hi @jacksonan123,

 

Unlike the old RANNOR function, the RAND function allows you to specify the (mean and) standard deviation within the function call:

eps1=rand('normal',0,sqrt(feps1));
jacksonan123
Lapis Lazuli | Level 10
I received the following reply:

Is your concern about controlling the seed of the Rand('Normal') ? If not
the equivalent code would be :

eps1 = rand('Normal') * sqrt(feps1);

Which is the same as yours (without the mean), but the issue for me which I
failed to initially clearly state would be to control the seed as
indicated in the response.
ballardw
Super User

@jacksonan123 wrote:
I received the following reply:

Is your concern about controlling the seed of the Rand('Normal') ? If not
the equivalent code would be :

eps1 = rand('Normal') * sqrt(feps1);

Which is the same as yours (without the mean), but the issue for me which I
failed to initially clearly state would be to control the seed as
indicated in the response.

If you need to repeat the stream of random numbers you would use Call Streaminit(seedvalue) before calling any of the RAND functions. However there is only one stream sequence of random numbers created.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1860 views
  • 1 like
  • 4 in conversation