Programming the statistical procedures from SAS

Generate Random variable

Reply
Occasional Contributor HM3
Occasional Contributor
Posts: 9

Generate Random variable

How to generate random var in a matrix (20*30) form having mean=3 and standard dev=1.

Thanks

Parth

SAS Super FREQ
Posts: 3,306

Generate Random variable

You don't specify the distribution, but I assume you want normally distributed values from N(3,1)? Here is a PROC IML solution:

proc iml;

x = j(20, 30);  /* allocate 20x30 matrix */

call randseed(123); /* seed random seed */

call randgen(x, "Normal", 3, 1); /* N(3,1) */

For more about generating random samples, see http://blogs.sas.com/content/iml/2010/09/22/efficient-sampling/

If you one day want a sample from a multivariate normal distribution, see http://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution/

Ask a Question
Discussion stats
  • 1 reply
  • 121 views
  • 0 likes
  • 2 in conversation