BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Abdulla1
Quartz | Level 8

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

Abdulla1_1-1647285295253.png

 

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
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

5 REPLIES 5
Abdulla1
Quartz | Level 8

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;

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Abdulla1
Quartz | Level 8

There are many function that I have never used before here. Thank you very much. I learned a lot from your code

Abdulla1
Quartz | Level 8

that is a great way of visualizing the output. I really appreciate your input. 

thanks

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1876 views
  • 2 likes
  • 3 in conversation