Help using Base SAS procedures

Kappa and percent agreement for multiple variables

Accepted Solution Solved
Reply
Contributor
Posts: 67
Accepted Solution

Kappa and percent agreement for multiple variables

[ Edited ]

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


Accepted Solutions
Solution
‎02-20-2016 03:38 PM
Respected Advisor
Posts: 4,659

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

View solution in original post


All Replies
Super User
Posts: 9,687

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?

Respected Advisor
Posts: 4,659

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
Solution
‎02-20-2016 03:38 PM
Respected Advisor
Posts: 4,659

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
Contributor
Posts: 67

Re: Kappa and percent agreement for multiple variables

Thank you so much - stay blessed - you saved me so much time -
Best Regards
Contributor
Posts: 67

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

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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