Hello,
I am trying to generate a data set for a two factor random-effects model. The closest I have been able to get is:
data part1;
do i=1 to 3;
do j=1 to 9;
do k=1 to 2;
a=rannor(1);
b=rannor(1);
c=rannor(1);
e=rannor(1);
x=a+b+c+e;
output;
end;
end;
end;
run;
However, this doesn't work because, for example, a will equal something different every time that i=1. I believe that I need to have the same random a for every i, b for every j, and c for every k. How do I do this?
Thank you everyone
Something like this?
data part1;
array A [*] A1-A3;
array B [*] B1-B9;
array C [*] C1-C2;
do I=1 to dim(A);
A[I]=rannor(1);
end;
do I=1 to dim(B);
B[I]=rannor(1);
end;
do I=1 to dim(C);
C[I]=rannor(1);
end;
do I=1 to dim(A);
do J=1 to dim(B);
do K=1 to dim(C);
E=rannor(1);
X=A[I]+B[J]+C[K]+E;
output;
end;
end;
end;
run;
This seems to be almost exactly what I was looking for. I had meant to specify that c is actually the a*b interaction term though-there is no actual term c. So this would lead me to believe that I would need to do c=1 to 27 to get every combination of a*b. But when I do that I get 729 entries. Do you have any suggestions on how to accomplish this?
Then this:
data part1;
array B [*] B1-B9;
do I=1 to dim(B);
B[I]=rannor(1);
end;
do I=1 to dim(A);
A=rannor(1);
do J=1 to dim(B);
C=rannor(1);
E=rannor(1);
X=A+B[J]+C+E;
output;
end;
end;
run;
C is unique and constant for each A and B combination, but that's probably not what you meant as there is now no logical difference between C and E.
Or this, but the comment about C and E being equivalent still stands
I hope you can modify one of these to do what you want (assuming you know what you want).
data part1;
array A [*] A1-A3;
array B [*] B1-B9;
array C [3,9,2] ;
do I=1 to dim(A);
A[I]=rannor(1);
end;
do I=1 to dim(B);
B[I]=rannor(1);
end;
do I=1 to dim(A);
do J=1 to dim(B);
do K=1 to 2;
C[I,J,K]=rannor(1);
E=rannor(1);
X=A[I]+B[J]+C[I,J,K]+E;
output;
end;
end;
end;
run;
I see what you are saying about c and e being equivalent. Thanks for the help!
Which variables are fixed effects and which are random effects?
The general rule is that the random effects change for each level of district/school/classroom/student.
A and b are both random, and c is actually the interaction term. This is actually more of a theoretical exercise. It would make sense though that for each level of a, the random effect will be the same for all y's corresponding to that level of a?
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 25. Read more here about why you should contribute and what is in it for you!
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.