0

I know this is simple but I can't seem to figure it out.

I have a dataset that has 50 students, and one of the columns is called test score which has a test score for each of the students. I need to go through and find the difference between all of the students- so student 1 score- student 2 score, student 2 score-student 3 score..... to 50 then student 2 score-student 3 score,... student 2 score-student 50 score.

I essentially need to end up with a matrix of differences for the test scores.

I have to use an array- so it would be something like Data: Student Score Alejandro 91 Atkinsin 87 Beal 72 Butler 94 Coleman 91

data array;
set testscores;
array score(50) Score1-Score 50; ?I dont think this is correct
do i=1 to 50;
difference= score(i) -score(i+1)?? I really have no idea everything I try isn't working 
end;
run;

I need to end up with something that has the difference between every students scores

hk47
  • 127
  • 3
  • 14
  • The code depends on your data structure. You need to show sample data. This also sounds like a distance matrix so a proc distance may be the easiest method. – Reeza Mar 10 '16 at 03:17
  • I agree with Reeza, adding some sample data will greatly improve your chances of getting help. – Dominic Comtois Mar 10 '16 at 05:04

1 Answers1

0

The first data step generates random scores between 1 (a) and 100 (b) following the uniform distribution for 50 students.

Then proc distance calculates the differences between the score of each student with all other students. For this to work, "Student" should be a character variable.

data scores;
    a = 1;
    b = 100;
    do Student_temp = 1 to 50;
        Student = compress(put(student_temp, 8.));
        u = ranuni(12345);
        Score = floor(a + (b-a)*u);
        output;
    end;
    drop Student_temp a b u;
run;

proc distance data=scores out=Diff method=Euclid;
    var interval(score);
    id Student;
run;