Choose Language Hide Translation Bar Super User Joined:

Mar 17, 2015

## Calculating Concordance (C-index) for cox models

I'm trying to calculate concordance index in JMP 10 of a cox model.  I found this paper for SAS:

http://support.sas.com/resources/papers/proceedings09/236-2009.pdf

but am not quite understanding what it is that it's doing.   Any help is appreciated.

```proc sql;
create table allset as
select idn_j, y_j, x_j, idn as idn_i, surv as y_i, combdays as x_i
from evtset, obs
where idn_j<>idn;
quit;
data concord;
set allset;
if (x_i<x_j and y_i>y_j) or (x_i>x_j and y_i<y_j) then concord=1;
else concord=0;
run;

data _null_;
set concord end=eof;
retain nch ndh;
if _N_=1 then do;
nch=0;
ndh=0;
end;
if concord=1 then nch+1;
if concord=0 then ndh+1;
if eof=1 then do;
call symput('ch',trim(left(nch)));
call symput('dh',trim(left(ndh)));
call symput('uspairs',trim(left(_n_)));
end;
run;
data _null_;
set sample end=eof;
if eof=1 then call symput('totobs',trim(left(_n_)));
run;
%put &ch &dh &uspairs &totobs;
data calculat;
ch=input("&ch",12.0);
dh=input("&dh",12.0);
uspairs=input("&uspairs",12.0);
totobs=input("&totobs",10.0);
pc=ch/(totobs*(totobs-1));
pd=dh/(totobs*(totobs-1));
c_hat=pc/(pc+pd);

w=(2*1.96**2)/(totobs*(pc+pd));
low_ci_w=((w+2*c_hat)/(2*(1+w)))-(sqrt((w**2+4*w*c_hat*(1-
c_hat))/(2*(1+w))));
upper_ci_w=((w+2*c_hat)/(2*(1+w)))+(sqrt((w**2+4*w*c_hat*(1-
c_hat))/(2*(1+w))));
run; ```
1 ACCEPTED SOLUTION

Accepted Solutions Super User Joined:

Jun 22, 2012

Solution

## Re: Calculating Concordance (C-index) for cox models

Here is my review of the SAS code

``````//This step does a cartesian join of the evtset and obs data tables,
// but eliminates any rows where the column idn_j=idn
// To do this in JMP would be a 2 step process.  Use
//  Tables==>Join
// and specify to perform a Cartesian Join, then find all rows in
// the new data table where idn_j==idn and delete them
proc sql;
create table allset as
select idn_j, y_j, x_j, idn as idn_i, surv as y_i, combdays as x_i
from evtset, obs
where idn_j<>idn;
quit;

// This step just creates a new column called "concord"
// SAS has to create a new table to do this, where JMP could
// just add it to the allset data table from the join step
data concord;
set allset;
if (x_i<x_j and y_i>y_j) or (x_i>x_j and y_i<y_j) then concord=1;
else concord=0;
run;

// This step simply creates macro variables for the number of rows
// that have been set to a concord value of 1 and 0 and a third
// variable as to the number of total rows
// JMP would just do this with 3 statements
// ch=N rows(allset<<get rows where(concord==1));
// dh=N Rows(allset)-ch;
// uspairs=N Rows(allset);
data _null_;
set concord end=eof;
retain nch ndh;
if _N_=1 then do;
nch=0;
ndh=0;
end;
if concord=1 then nch+1;
if concord=0 then ndh+1;
if eof=1 then do;
call symput('ch',trim(left(nch)));
call symput('dh',trim(left(ndh)));
call symput('uspairs',trim(left(_n_)));
end;
run;

// This step references the original data table "sample" which
// was the input table to the phreg procedure that was run on it.
// This step simply gets the numer of rows from that table
// JMP code would simply be
// totobs=nrows(sample);
data _null_;
set sample end=eof;
if eof=1 then call symput('totobs',trim(left(_n_)));
run;

// This simply writes out the calculated macro values
%put &ch &dh &uspairs &totobs;

// This step creates an output data table with one row with the columns
// being calculated starting with the macro variable values
data calculat;
ch=input("&ch",12.0);
dh=input("&dh",12.0);
uspairs=input("&uspairs",12.0);
totobs=input("&totobs",10.0);
pc=ch/(totobs*(totobs-1));
pd=dh/(totobs*(totobs-1));
c_hat=pc/(pc+pd);

w=(2*1.96**2)/(totobs*(pc+pd));
low_ci_w=((w+2*c_hat)/(2*(1+w)))-(sqrt((w**2+4*w*c_hat*(1-c_hat))/(2*(1+w))));
upper_ci_w=((w+2*c_hat)/(2*(1+w)))+(sqrt((w**2+4*w*c_hat*(1-c_hat))/(2*(1+w))));
run; ``````
Jim Super User Joined:

Jun 22, 2012

Solution

## Re: Calculating Concordance (C-index) for cox models

Here is my review of the SAS code

``````//This step does a cartesian join of the evtset and obs data tables,
// but eliminates any rows where the column idn_j=idn
// To do this in JMP would be a 2 step process.  Use
//  Tables==>Join
// and specify to perform a Cartesian Join, then find all rows in
// the new data table where idn_j==idn and delete them
proc sql;
create table allset as
select idn_j, y_j, x_j, idn as idn_i, surv as y_i, combdays as x_i
from evtset, obs
where idn_j<>idn;
quit;

// This step just creates a new column called "concord"
// SAS has to create a new table to do this, where JMP could
// just add it to the allset data table from the join step
data concord;
set allset;
if (x_i<x_j and y_i>y_j) or (x_i>x_j and y_i<y_j) then concord=1;
else concord=0;
run;

// This step simply creates macro variables for the number of rows
// that have been set to a concord value of 1 and 0 and a third
// variable as to the number of total rows
// JMP would just do this with 3 statements
// ch=N rows(allset<<get rows where(concord==1));
// dh=N Rows(allset)-ch;
// uspairs=N Rows(allset);
data _null_;
set concord end=eof;
retain nch ndh;
if _N_=1 then do;
nch=0;
ndh=0;
end;
if concord=1 then nch+1;
if concord=0 then ndh+1;
if eof=1 then do;
call symput('ch',trim(left(nch)));
call symput('dh',trim(left(ndh)));
call symput('uspairs',trim(left(_n_)));
end;
run;

// This step references the original data table "sample" which
// was the input table to the phreg procedure that was run on it.
// This step simply gets the numer of rows from that table
// JMP code would simply be
// totobs=nrows(sample);
data _null_;
set sample end=eof;
if eof=1 then call symput('totobs',trim(left(_n_)));
run;

// This simply writes out the calculated macro values
%put &ch &dh &uspairs &totobs;

// This step creates an output data table with one row with the columns
// being calculated starting with the macro variable values
data calculat;
ch=input("&ch",12.0);
dh=input("&dh",12.0);
uspairs=input("&uspairs",12.0);
totobs=input("&totobs",10.0);
pc=ch/(totobs*(totobs-1));
pd=dh/(totobs*(totobs-1));
c_hat=pc/(pc+pd);

w=(2*1.96**2)/(totobs*(pc+pd));
low_ci_w=((w+2*c_hat)/(2*(1+w)))-(sqrt((w**2+4*w*c_hat*(1-c_hat))/(2*(1+w))));
upper_ci_w=((w+2*c_hat)/(2*(1+w)))+(sqrt((w**2+4*w*c_hat*(1-c_hat))/(2*(1+w))));
run; ``````
Jim