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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.