BookmarkSubscribeRSS Feed
aya123
Calcite | Level 5
The following code is used to generate 50 vectors of size n and each vector is variable (E) having normal distribution with mean 0 and variance equals 1, so how can I generate this variable 50 times but when the variable (E) follows normal distribution with mean 0 and variance equals 4 ?

Do j=1 to 50;
E= normal(repeat(-1,n));
end;
2 REPLIES 2
nicolas_
Calcite | Level 5
You just multiply E by the square root of the variance, i.e. E=2#normal(repeat(-1,n));

A linear transformation aX+b of a normal variable X is again normally distributed with mean equal to a*mean(X) + b and variance equal to a^2*var(X)
Rick_SAS
SAS Super FREQ
You can use the RANDGEN call, which includes optional arguments for the mean and Std Dev. You first need to allocate a vector to store the data:
proc iml;
n=10;
E = j(n,1);
do i = 1 to 50;
call randgen(E, "Normal", 0, 4);
end;

You can also get all 50 variables at once. Each column of the following matrix contains a sample from N(0, 4).

E = j(n,50);
call randgen(E, "Normal", 0, 4);

For comments on generating random vectors efficiently, see
http://blogs.sas.com/iml/index.php?/archives/9-Efficient-Sampling.html

For a description of how to generate 50 variables that each have a different distribution, see
http://blogs.sas.com/iml/index.php?/archives/117-How-to-Sample-from-Independent-Normal-Distributions...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 786 views
  • 0 likes
  • 3 in conversation