BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AZIQ1
Quartz | Level 8

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

... 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

5 REPLIES 5
Ksharp
Super User

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

Transpose your data to this structure

 

id varName rating_A rating_B

 

and use proc freq, by varName.

PG
PGStats
Opal | Level 21

... 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
AZIQ1
Quartz | Level 8
Thank you so much - stay blessed - you saved me so much time -
Best Regards
AZIQ1
Quartz | Level 8

Thanks again,

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

 

Thanks

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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