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;
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).
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).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.