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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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