06-23-2017 12:16 PM - edited 06-23-2017 12:20 PM
I have this code which, given an input covariance matrix, randomly draws 1000 values for each of four normally-distributed variables. It's easy enough to change the seed manually to generate another set of 1000 random variable values, but I'm looking to create 1000 or more of these such sets, and to average them together. Can this be done with a sort of loop or macro? Any ideas as to how to go about automating this? Please share. Thanks for your help!
Data RandomValueGeneratorStatistics (type=COV); input _TYPE_ $ _NAME_ $9. variable1 variable2 variable3 variable4; datalines; COV variable1 0.999368288 0.009398213 0.075083647 0.453177098 COV variable2 0.009398213 0.000155024 0.000878636 0.006372190 COV variable3 0.075083647 0.000878636 0.008894056 0.043200581 COV variable4 0.453177098 0.006372190 0.043200581 0.999368288 MEAN 3.217123172 42.69388108 3.893316488 8605.147733 ; run; Proc Simnorm data=RandomValueGeneratorStatistics outsim=ssim numreal = 1000 seed = 54321; var variable1 variable2 variable3 variable4; run;
06-23-2017 01:13 PM
Thanks for your response @WarrenKuhfeld. Yes, that could be done, but I would like to vary the seed to average-out the biases (some of the psuedorandomness) of any single seed. Or is this logic flawed? What role does the seed play in the generation of random values, precisely?
In any case, as I'm entirely new to SAS, this could be a great learning experience for me as it pertains to loops/macros.
Thanks so much for your help.
06-23-2017 01:18 PM
You need to understand random number streams in general, not specifically for SAS.
A seed sets the initial value, so you always get the same 'random' numbers with the same seed.
Using a seed allows you to replicate the stream to verify your results.
So changing the seed in a process doesn't quite make sense because you're likely going to either set those manually or not be able to replicate the data.
06-23-2017 01:22 PM
Check out one of Rick Wicklin's several blogs on seeds. http://blogs.sas.com/content/iml/2017/06/01/choose-seed-random-number.html
I would recommend doing vanilla DATA step programming to get your results rather than using a macro. There are plenty of opportunities for macro loops when they are really needed. I don't know off hand how simnorm generates random numbers. However, if you want to see the strange things that might happen if you pick the wrong seed combinations with the old rannor/ranuni style functions, see the graphs in this page. I love the "bug plot" about half way down.
06-23-2017 01:34 PM
Looks like I failed to post the link. This page does answer some of your questions about seeds and what can go wrong when you change seeds.
06-23-2017 01:38 PM
If you're doing simulations in SAS this is a good foundational paper to read: