Help using Base SAS procedures

proc corr/reg by group

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 98
Accepted Solution

proc corr/reg by group

Hi community,

I am trying to examine correlation between two variables by group, and there are over 100 groups. What would be a quick and efficient to do that rather than running corr/reg group by group?

For example, I have variables group, var1 and var2 in data "have". There are over 100 groups (1-150), and each group has around 50 observations. I need to get correlation between var1 and var2 by group. My dumb way is:

proc corr data=work.have;

     var var1 var2;

    where group=1;

run;

Thank you all.

Lizi


Accepted Solutions
Solution
‎06-29-2015 11:00 AM
Super User
Posts: 19,789

Re: proc corr/reg by group

proc corr data=work.have;

     var var1 var2;

    BY GROUP;

run;

View solution in original post


All Replies
Solution
‎06-29-2015 11:00 AM
Super User
Posts: 19,789

Re: proc corr/reg by group

proc corr data=work.have;

     var var1 var2;

    BY GROUP;

run;

Frequent Contributor
Posts: 98

Re: proc corr/reg by group

I guess my question should be: is it possible to format the correlation coefficient result as below:

Groupcorr_coeff
1corr1
2corr2
3corr3

....

up to as many groups as I have.

Thanks again!

Respected Advisor
Posts: 2,655

Re: proc corr/reg by group

If you use BY group processing, then adding an ODS output statement should accomplish what you need:

proc corr data=work.have;

     var var1 var2;

     BY GROUP;

     ODS OUTPUT PearsonCorr=PearsonCorr;

run;

You can then post process the dataset pearsoncorr to contain only what you need.

Steve Denham

Frequent Contributor
Posts: 98

Re: proc corr/reg by group

Posted in reply to SteveDenham

You guys are AWESOME!

Thank you very much!

Respected Advisor
Posts: 2,655

Re: proc corr/reg by group

is awesome.  I just read the documentation really, really fast.

Steve Denham

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 347 views
  • 3 likes
  • 3 in conversation