I have a large simulation, that involves several data steps and a few loops.
I would like to set a single random number seed at the start of the simulation, and thus have a single reproducible stream of random numbers. How can I do this?
Here is the simulation, in pseudo-code
Loop 1
Data step A creating uniform random variables
Loop 2
Data step B creating more uniform random variables
More PROCs and Data steps
Data step C creating more uniform random variables
PROC SOMETHING
End of Loop 2
End of Loop 1
In fact, all procedures (or almost) will update the SYSRANEND macro variable. Although not perfect (check the documentation) this seems to be the best method to carry a seed from one procedure to the next. - PG
Perhaps you want to save the last SEED used at each step/interation as the SEED for the next.
If you use the CALL version of the random number function you can track the seed.
Also SURVEYSELECT will create macro variables with seed info.
In fact, all procedures (or almost) will update the SYSRANEND macro variable. Although not perfect (check the documentation) this seems to be the best method to carry a seed from one procedure to the next. - PG
Paige,
I had come up with the same idea as DataNull did .. i.e., capturing the latest seed in a datastep using call ranuni. The following code shows that it produces the same result as I think you are trying to achieve:
data part1;
seed=872643;
do i=1 to 10;
call ranuni(seed,random);
output;
end;
call symput('seed',seed);
run;
data part2;
seed=&seed.;
do i=1 to 10;
call ranuni(seed,random);
output;
end;
call symput('seed',seed);
run;
data part3;
seed=&seed.;
do i=1 to 10;
call ranuni(seed,random);
output;
end;
call symput('seed',seed);
run;
data test;
do i=1 to 30;
random=ranuni(872643);
output;
end;
run;
HTH,
Art
Example of using last seed as next seed with data steps.
Paige,
You got great solutions in an hour. You are the luckiest man today and should go out to buy lottery tickets.
Linlin wrote:
Paige,
You got great solutions in an hour. You are the luckiest man today and should go out to buy lottery tickets.
Statisticians don't believe in purchasing lottery tickets, the expected gain is negative, worse than just putting money in a savings account that pays 0.5% annually.
, Sure am glad I'm not a statistician. Conversely, putting money into a savings account that pays 0.5% annually, only has the potential of resulting in a loss when one considers the effects of inflation and the taxes one has to be on the interest. While the likelihood of winning the grand prize of tomorrow's Canadian lottery ($26 million) has rather poor odds ( 1 in 13,983,816) the potential IS a bit larger than a savings account, the psychological excitement about the possibility of winning exists and, in the unlikely event that one does actually win, the winnings are tax free.
Compared to my friends who regularly play the lottery and football pools and the like, I have not lost a single penny, while they have lost thousands of dollars. I like my situation better than theirs.
My ex-mother-in-law bought 5 dollars in Lottery tickets every week that I knew her. Once I asked her if she ever won anything, and she very enthusiastically replied that Yes, once, she won $50.
Good luck with your lottery tickets.
I'm wondering where I can get 0.5% on a savings account. Locally with my balance it's closer to 0.01%.
Of course if I only buy a lottery ticket with the max payout is large enough then the expected winning become positive. But living long enough to play enough times ...:smileylaugh:
One quote I like:
"Limits on knowledge and computation are central to the human condition."
by Herbert A. Simon in Models of Bounded Rationality: Empirically grounded economic reason, MIT Press, 1982
Many profitable industries depend on those limits: insurance, lotteries and casinos, marketing, stock trading, to name a few. And I never forget that some might want to add statistics to the list.
PG
This is covered on p. 33-34 of my book. Assuming that "Loop 1" is a macro loop, I think you can get rid of it and gain some efficiency in your simulation by using BY processing. See Chapter 6 of my book or see the article Simulation in SAS
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.