sas

SAS largest correlation not equal to 1


Suppose I have dataset have which contains cross-correlations (obtained from a proc corr output):

  _NAME_    A      B      C
  A         1      0.2    0.8
  B         0.2    1      0.3
  C         0.8    0.3    1

I am trying to calculate the largest correlation value

 data want;
 set have;
 max_corr = max(of A B C);
 run;

Which produces:

  _NAME_    A      B      C     max_corr
  A         1      0.2    0.8   1
  B         0.2    1      0.3   1
  C         0.8    0.3    1     1

However, this value is 1 for each row, which is expected as the correlation across the diagonal is 1. How can I adjust the code to show the largest correlation not equal to 1?

For example, I'm looking for

  _NAME_    A      B      C     max_corr
  A         1      0.2    0.8   0.8
  B         0.2    1      0.3   0.3
  C         0.8    0.3    1     0.8

Solution

  • You can use the largest function.

    data corr;
       input _NAME_ $   A      B      C;
       max_corr = largest(2,of a b c);
       cards;
      A         1      0.2    0.8
      B         0.2    1      0.3
      C         0.8    0.3    1
    ;;;;
       run;
    proc print;
       run;
    

    enter image description here