bobguy 发表于 2010-1-17 06:55 
elliott828 发表于 2010-1-17 05:46 
2# bobguy
谢谢你bobguy!
但是按照你的code做出来结果是一个只有三个变量关系的表格:
data pearson;
set corr1;
array corr(*) age weight;
i=_n_;
do j=i to dim(corr);
corr_name=compress(_name_||'*'||vname(corr(j)));
corrcoef=corr(j);
output;
end;
if i=dim(corr) then stop;
run;
这是我用的code,稍微改了一下变量。
如何才能按照这种格式显示所有变量间的相关系数呢?
另外,如果把这个code应用到macro里面,如何处理变量名呢?我的意思是,对不同的数据,变量的名字和数量都不一样,如何用一种code来处理所有数据呢?
谢谢啦!
Suppose you have 5 variables namely, x1 x2 x3 x4 x5
The information you want is the up-diagonal elements.
1) outp=pearson(where=(_TYPE_='CORR')); ** this where is needed to keep only information about correlations.
2) array corr(*) Height Weight ; ***change this into array corr(*) x2 x3 x4 x5 ;
I add a little bit in details
A sas table can be think of two dimesional arrays or matrix {i,j}
when one needs elements of off diagnal up-top of a correaltion matrix, one only needs to read (n^2-n)/2 elements since it is symmetric. n is for the number of variance elements and 1/2 is for symmetric.
So the column index goes from 2 to n having n-1 elements. That is,
array corr(*) Height Weight ; **** start from second one in correaltion matrix.
The row index goes from 1 to n-1 having n-1 elements. That is SAS data set internal loop.
i=_n_;
if i=dim(corr) then stop; *** The last row having no information for correaltion.
Hope this is clear.