## the ways include proc corr and reg, etc;
## requesting only pearson correlation coef. can be solved by data step;
- data have1;
- set have;
- if mod(_n_, 10) =1 then grp10 ++1;
- if cmiss(x, y) then call missing(x, y); *delete any missing;
- run;
- data have2;
- array tx[10] _temporary_; array ty[10] _temporary_;
- call missing(of tx[*]); call missing(of ty[*]);
- do until(last.grp10);
- set have1;
- by grp10;
- num =sum(num, 1);
- tx[num] =x; ty[num] =y;
- end;
- meanX =mean(of tx[*]); stdX =std(of tx[*]);
- meanY =mean(of ty[*]); stdY =std(of ty[*]);
- n =n(of tx[*]);
- do until(last.grp10);
- set have1;
- by grp10;
- sum2 =sum(sum2, (x -meanX)*(y -meanY));
- end;
- if n >1 then if (stdX & stdY) then r =sum2/((n-1) *stdX *stdy);
- keep grp10 r;
- run;
复制代码所得的结果应该等同于proc corr nomiss。
所有的代码不保证准确性。无法在sas里调试。只是希望有所参考。
京剧