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
proc corr data=work.have;
var var1 var2;
BY GROUP;
run;
I guess my question should be: is it possible to format the correlation coefficient result as below:
Group | corr_coeff |
1 | corr1 |
2 | corr2 |
3 | corr3 |
....
up to as many groups as I have.
Thanks again!
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
You guys are AWESOME!
Thank you very much!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.