SAS Procedures

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

proc corr data=work.have;

     var var1 var2;

    BY GROUP;

run;

View solution in original post

5 REPLIES 5
Reeza
Super User

proc corr data=work.have;

     var var1 var2;

    BY GROUP;

run;

lizzy28
Quartz | Level 8

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!

SteveDenham
Jade | Level 19

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

lizzy28
Quartz | Level 8

You guys are AWESOME!

Thank you very much!

SteveDenham
Jade | Level 19

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

Steve Denham

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12016 views
  • 6 likes
  • 3 in conversation