BookmarkSubscribeRSS Feed
PBG
Obsidian | Level 7 PBG
Obsidian | Level 7

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;

 

8 REPLIES 8
WarrenKuhfeld
Rhodochrosite | Level 12

Can't you just generate 1000 x 1000 observations in one data set and then process them?  Why change the seed?

PBG
Obsidian | Level 7 PBG
Obsidian | Level 7

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.

Reeza
Super User

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.

 

 

WarrenKuhfeld
Rhodochrosite | Level 12

 


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.

PBG
Obsidian | Level 7 PBG
Obsidian | Level 7
Thank you both for your help.
WarrenKuhfeld
Rhodochrosite | Level 12

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001281561.htm

 

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.

Reeza
Super User

If you're doing simulations in SAS this is a good foundational paper to read:

 

http://www2.sas.com/proceedings/forum2007/183-2007.pdf

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1609 views
  • 10 likes
  • 3 in conversation