## Kappa and percent agreement for multiple variables

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

1 ACCEPTED SOLUTION

Accepted Solutions  PGStats
Opal | Level 21

## Re: Kappa and percent agreement for multiple variables

... 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;
``````
PG
5 REPLIES 5  Ksharp
Super User

## Re: Kappa and percent agreement for multiple variables

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?  PGStats
Opal | Level 21

## Re: Kappa and percent agreement for multiple variables

Transpose your data to this structure

id varName rating_A rating_B

and use proc freq, by varName.

PG  PGStats
Opal | Level 21

## Re: Kappa and percent agreement for multiple variables

... 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;
``````
PG

## Re: Kappa and percent agreement for multiple variables

Thank you so much - stay blessed - you saved me so much time -
Best Regards

## Re: Kappa and percent agreement for multiple variables

Thanks again,

Now I want to add third rater any insights how to change the array statement?

Thanks

Discussion stats
• 5 replies
• 2687 views
• 1 like
• 3 in conversation