BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CathyVI
Pyrite | Level 9

Hello,

Am trying to simulate 1000 copies of three variables x1, x2, and x3 with variances equal to 9. I can choose any mean. How do I do this in sas?

I created this simulation code but I don't know how to include variance =9 or chose any mean. Thanks for your help.

data a;
do i=1 to 1000;
y1=rannor(0);
y2=rannor(0);
y3=rannor(0);
output;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can use the RAND function with the 'normal' option, and then its pretty easy to specify any variance. So in this case, you would specify the lambda parameter to be 3.

 

The way you were doing it, using the RANNOR function, you are creating a normal random variable which has a standard deviation of 1, and the documentation includes an example of how to get a specific variance. So, its always a good idea to check the documentation. To obtain a variance of 9, you would just multiply the result by the constant value ____ (you fill in the blank).

 

 

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

You can use the RAND function with the 'normal' option, and then its pretty easy to specify any variance. So in this case, you would specify the lambda parameter to be 3.

 

The way you were doing it, using the RANNOR function, you are creating a normal random variable which has a standard deviation of 1, and the documentation includes an example of how to get a specific variance. So, its always a good idea to check the documentation. To obtain a variance of 9, you would just multiply the result by the constant value ____ (you fill in the blank).

 

 

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 498 views
  • 0 likes
  • 2 in conversation