Programming the statistical procedures from SAS

how can I extract name of correlated variables?

Reply
Occasional Contributor
Posts: 8

how can I extract name of correlated variables?

Hi

I have a data set like

A        B      C     D     E

1        12     3.2     ....

1.5     10     4

1.3     11     5.6

.

.

.

I want to extract name of correlated variables from it

for example I want a result like this:

A B

C D

E

which means A&B are correlated, C&D are correlated and E in independent

I used proc corr to have correlation matrix but I don't know how can I extract name of correlatd variables from it.

Can anybody help me in this issue?

Thanks a lot

Respected Advisor
Posts: 3,773

Re: how can I extract name of correlated variables?

This works but It seems like I remember an easier way, oh well. :smileyplain: 

ods output  PearsonCorr= PearsonCorr;

proc corr data=sashelp.heart;

   run;

ods output close;

proc transpose out=probs;

   by variable notsorted;

   var PAgeCHDdiag--PCholesterol;

   run;

data probs(keep=Variable With);

   set probs;

   by variable notsorted;

   if first.variable then do;

      i + 1;

      j = 0;

      end;

   j + 1;

   if i ge j then delete; *Upper;

   if col1 gt .05 then delete; *Cutoff;

   length With $32;

   with = substr(_name_,2);

   run;

options byline=1;

proc print;

   by variable notsorted;

   id variable;

   run;

Super Contributor
Posts: 1,636

Re: how can I extract name of correlated variables?

data have;

infile cards missover;

input A B C D E;

cards;

1 12 3.2 . .

1.5 10 4 . 8

1.3 11 5.6 7 9

;

run;

data ab (rename=(a=var1 b=var2));

  set have(keep=a b);

  i=_n_;

  group=1;

data cd (rename=(c=var1 d=var2));

  set have(keep=c d);

  i=_n_;

  group=2;

data e (rename=(e=var1));

  set have(keep=e);

  i=_n_;

  group=3;

data want (keep=varSmiley Happy;

set ab cd e;

by i group;

run;

proc print;

run;

Linlin

Grand Advisor
Posts: 9,466

Re: how can I extract name of correlated variables?

You need variable cluster method.

proc varclus

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 4 in conversation