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


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2007 views
  • 1 like
  • 3 in conversation