BookmarkSubscribeRSS Feed
bdp
Calcite | Level 5 bdp
Calcite | Level 5

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



7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

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;

 

 

bdp
Calcite | Level 5 bdp
Calcite | Level 5

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?

ChrisNZ
Tourmaline | Level 20

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.

ChrisNZ
Tourmaline | Level 20

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;

 

bdp
Calcite | Level 5 bdp
Calcite | Level 5

I see what you are saying about c and e being equivalent. Thanks for the help!

Rick_SAS
SAS Super FREQ

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. 

 

 

bdp
Calcite | Level 5 bdp
Calcite | Level 5

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?

sas-innovate-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 7 replies
  • 3365 views
  • 0 likes
  • 3 in conversation