Your situation is too complicated for me to debug, so here is some general advice for developing and debugging your program:
1. Resolve the missing value issue. You can't do matrix multiplication with missing values.
2. Use 4 teachers, not 15
3. Use 5 replicates, not 1000.
4. Add a SampleID variable to the data sets. That will make it easier to keep track of which observations correspond to which sample. For example, in the covariance data, the first three observations have SampleID=1, the next three have SampleID=2, and so forth.
5. Include a DATA step so that others can run your program.
For large data sets, the most efficient way to perform "BY-group processing" in SAS/IML is to use the UNIQUEBY function.
Because you know the number of obs in each data set, you don't necessarily need to use UNIQUEBY, but I mention it because the article has an example and discussion that might be relevant to your problem.
... View more