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:)


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1914 views
  • 1 like
  • 3 in conversation