Hi,
I wanted to know how can I run kappa and percent agreement on multiple variables and get the output all in one.
eg. my data looks like this (rater A and rater B) and there are 3 different vars ( I have > 20 variables in the actual dataset) :
id var1_A var2_B ... var2_A ... var2_B ... var3_A ...var3_B
I want the output like this:
Kappa percent agreement
var1
var2
var3
Thanks
... For example:
/* Example data */
data test;
call streaminit(8687);
do id = 1 to 10;
array v Var1_A Var1_B Var2_A Var2_B Var3_A Var3_B;
do i = 1 to dim(v);
v{i} = rand("Poisson", 2);
end;
output;
end;
drop i;
run;
proc print data=test noobs; run;
/* Transpose, assuming variables are named variableName_raterName */
data long;
set test;
array v Var1_A -- Var3_B;
do i = 1 to dim(v) by 2;
var = scan(vname(v{i}), 1, "_");
val_A = v{i};
val_B = v{i+1};
output;
end;
keep var val_A val_B;
run;
proc print data=long(obs=6) noobs; run;
/* Call freq to get Kappa between A and B, get kappa table with ODS */
proc sort data=long; by var; run;
proc freq data=long;
by var;
table val_A*val_B / noprint agree plots=none;
ods output KappaStatistics=kappa;
run;
proc print data=kappa noobs; run;
/* Print Kappa table */
proc sql;
select
var length=16,
value "Kappa",
max(0, value) "Percent agreement" format=percent7.1
from kappa
where statistic = "Simple Kappa";
quit;
You didn't post sample data yet .
And remember KAPPA is only for square contingecy table .
It looks like you need some data step code not proc freq?
Transpose your data to this structure
id varName rating_A rating_B
and use proc freq, by varName.
... For example:
/* Example data */
data test;
call streaminit(8687);
do id = 1 to 10;
array v Var1_A Var1_B Var2_A Var2_B Var3_A Var3_B;
do i = 1 to dim(v);
v{i} = rand("Poisson", 2);
end;
output;
end;
drop i;
run;
proc print data=test noobs; run;
/* Transpose, assuming variables are named variableName_raterName */
data long;
set test;
array v Var1_A -- Var3_B;
do i = 1 to dim(v) by 2;
var = scan(vname(v{i}), 1, "_");
val_A = v{i};
val_B = v{i+1};
output;
end;
keep var val_A val_B;
run;
proc print data=long(obs=6) noobs; run;
/* Call freq to get Kappa between A and B, get kappa table with ODS */
proc sort data=long; by var; run;
proc freq data=long;
by var;
table val_A*val_B / noprint agree plots=none;
ods output KappaStatistics=kappa;
run;
proc print data=kappa noobs; run;
/* Print Kappa table */
proc sql;
select
var length=16,
value "Kappa",
max(0, value) "Percent agreement" format=percent7.1
from kappa
where statistic = "Simple Kappa";
quit;
Thanks again,
Now I want to add third rater any insights how to change the array statement?
Thanks
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.