BookmarkSubscribeRSS Feed
James1214
Fluorite | Level 6

For my homework in my computing class, I need to use SAS function to generate 100 observations from a normal distribution with mean 20 and standard deviation 10.

This is what I have so far in my code.

%LET N = 100;                                 /* size of sample    */

Data Rand(keep=x u);

call streaminit(4321); /* set seed */

DO I = 1 to 100; /* generate 100 random values */

x = rand("Normal"); /* x ~ N(0,1) */

u = rand("Uniform"); /* u ~ U(0,1) */

output;

end;

run;

proc print;

run;

Can someone please help me with how do I make my code have the mean = 20 and standard deviation = 10?

Please let me know.

Thank you:)

3 REPLIES 3
Rick_SAS
SAS Super FREQ

To sample from a normal distribution with mean=20 and stddev=10, use

 

x = rand("Normal", 20, 10);

 

Of course, the SAMPLE will not have exactly the same mean and std dev, because it is a random sample.

 

Reeza
Super User

You declared a macro variable N but didn’t use it, was that intentional? 

 


@James1214 wrote:

For my homework in my computing class, I need to use SAS function to generate 100 observations from a normal distribution with mean 20 and standard deviation 10.

This is what I have so far in my code.

%LET N = 100;                                 /* size of sample    */

Data Rand(keep=x u);

call streaminit(4321); /* set seed */

DO I = 1 to 100; /* generate 100 random values */

x = rand("Normal"); /* x ~ N(0,1) */

u = rand("Uniform"); /* u ~ U(0,1) */

output;

end;

run;

proc print;

run;

Can someone please help me with how do I make my code have the mean = 20 and standard deviation = 10?

Please let me know.

Thank you:)