Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-06-2011 10:13 AM
(785 views)

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;

Do j=1 to 50;

E= normal(repeat(-1,n));

end;

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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)

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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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...

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...

**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.

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.