Hi, I have a data like below:
person i1 i2 i3 i4
1 1 2 3 4
2 3 2 4 1
3 2 1 3 4
4 4 1 2 3
Each person needs to rank the four things (i1, i2, i3, i4), for example, if the person thinks i4 is the best, then put 1 for i4; if the person thinks i3 is the second best, the put 2 for i3; if the person think i1 is the third best, the put 3 for i1; if the person think i2 is the worst, then put 4 for i2. So the rank of four things (i1-i4) for this person is 3 4 2 1.
I want to compute Kendall's W for the data like this, do you know the code for SAS? I checked online, PROC FREQ and PROC CORR can be used, but the data seems different from mine. Does anyone know how to do it? Thank you!
Hi @SAS-questioner,
Here's the code you can use once you have compiled the %MAGREE macro recommended by StatDave:
data have;
input person i1 i2 i3 i4;
cards;
1 1 2 3 4
2 3 2 4 1
3 2 1 3 4
4 4 1 2 3
;
proc transpose data=have name=item out=want(rename=(col1=rank));
by person;
var i1-i4;
run;
%magree(data=want,
items=item, raters=person, response=rank,
stat=kendall, options=wcl)
Main part of the output:
Kendall's Coefficient of Concordance for ordinal response Coefficient Lower Upper of Num Den Standard Confidence Confidence Concordance F DF DF Prob>F Error Limit Limit 0.3 1.286 2.5 7.5 0.3406 0.34233 0 0.97095
As always with questions of statistic availability, check the link to the list of Frequently Asked-for Statistics (FASTats) at the top of the Statistical Procedures Community page. You will find Kendall's coefficient of concordance there pointing to a macro that can be used to compute it.
Hi @SAS-questioner,
Here's the code you can use once you have compiled the %MAGREE macro recommended by StatDave:
data have;
input person i1 i2 i3 i4;
cards;
1 1 2 3 4
2 3 2 4 1
3 2 1 3 4
4 4 1 2 3
;
proc transpose data=have name=item out=want(rename=(col1=rank));
by person;
var i1-i4;
run;
%magree(data=want,
items=item, raters=person, response=rank,
stat=kendall, options=wcl)
Main part of the output:
Kendall's Coefficient of Concordance for ordinal response Coefficient Lower Upper of Num Den Standard Confidence Confidence Concordance F DF DF Prob>F Error Limit Limit 0.3 1.286 2.5 7.5 0.3406 0.34233 0 0.97095
Check @Rick_SAS blogs:
On computing Kendall's tau statistic in SAS - The DO Loop
Weak or strong? How to interpret a Spearman or Kendall correlation - The DO Loop (sas.com)
data have;
input person i1 i2 i3 i4;
cards;
1 1 2 3 4
2 3 2 4 1
3 2 1 3 4
4 4 1 2 3
;
proc transpose data=have name=item out=temp(rename=(col1=rank));
by person;
var i1-i4;
run;
proc freq data=temp noprint;
table item*rank/out=want sparse;
run;
proc freq data=want;
weight count;
tables item*rank / measures CL norow nocol nopercent;
run;
As Freelance said, If you are looking for Kendall's W. Check %magree macro.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.