Hello
I have a datasets that contains over 220 variables (include dummies that represents nominal). however, I would like to create a table that highlights highly correlated data (with |correlation| >60%) only.
as an example, if I ran the following code:
data have;
input v1-v7;
cards;
1 4 5 33 6 1 0
9 11 32 5 4 1 0
0 4 5 4 77 0 0
1 2 9 9 5 1 1
;
run;
proc corr data = have OUTP= corr;
var v1-v7;
run;
if I ran the code above I'll get
what I'm trying to generate is the following table:
| VARIABLE1 | VARIABLE2 | CORR |
| V1 | V2 | 0.95 |
| V1 | V3 | 0.99 |
| V2 | V3 | 0.92 |
| V5 | V6 | -0.99 |
Create a list, which only has abs(correlations) above a certain cutoff.
EXAMPLE
proc corr data=sashelp.class noprob nosimple;
var age height weight;
ods output pearsoncorr=corrs;
run;
data want;
set corrs;
length variable2 $ 32;
array r _numeric_;
do j=_n_+1 to dim(r);
corr=r(j);
variable2=vname(r(j));
if abs(corr)>0.6 then output;
end;
keep variable corr variable2;
run;
SORRY i DON'T KNOW WHY THE SAS CODE switched to this form:
here it is again:
data have;
input v1-v7;
cards;
1 4 5 33 6 1 0
9 11 32 5 4 1 0
0 4 5 4 77 0 0
1 2 9 9 5 1 1
;
run;
proc corr data = have OUTP= corr;
var v1-v7;
run;
Create a list, which only has abs(correlations) above a certain cutoff.
EXAMPLE
proc corr data=sashelp.class noprob nosimple;
var age height weight;
ods output pearsoncorr=corrs;
run;
data want;
set corrs;
length variable2 $ 32;
array r _numeric_;
do j=_n_+1 to dim(r);
corr=r(j);
variable2=vname(r(j));
if abs(corr)>0.6 then output;
end;
keep variable corr variable2;
run;
There are many function that I have never used before here. Thank you very much. I learned a lot from your code
that is a great way of visualizing the output. I really appreciate your input.
thanks
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.