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?
@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.
@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?
@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).
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 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.
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!
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.
Ready to level-up your skills? Choose your own adventure.