Dear Rick,
thank you for this post.

I am conducting simulations to compare methods for cutoff estimation. One is kernel density estimation where I use the intersection of 2 pdfs as a cutoff. For these I want to estimate sensitivity and specificity or area under the curve =cutoff.

Your code works very well when I use a single sample, but I am unable to make it run over e.g. a 1000 simulations. Thus, I need to construct some kind of loop or by statement around it, so it gives me the output "by sampledID".

The second issue I am facing is that each sample has a different cutoff, therefore I have a second data set with the cutoffs by sampleID, which at the moment I need to enter manually.

To sum it up, I have 2 data sets, 1 with sampleID 1 to x, the values and densities for each sample from the proc kde output, and a 2. data set with the cutoffs and sampleID.
Is there any possibility to manage that with SAS?
I would like to create an output data set with sensitivity/specificity by sampleID.

IML code:

* Integrals of kernel estimates *;

data integral;
set kernel_final (where=(sampleid=1));
run;

proc iml;
/** read in kernel density estimate **/
** TN/Speci estimate **;
use integral;
read all var {marker0} into x;
read all var {density0} into y;
close integral;

start TrapIntegral(x,y);
N = nrow(x);
dx = x[2:N] - x[1:N-1];
meanY = ( y[2:N] + y[1:N-1] )/2;
return( dx` * meanY );
finish;

/** compute the integral over all x **/
Area = TrapIntegral(x,y);
print Area;

/** compute the integral for x < 35.855431998 **/
idx = loc(x = 35.855431998 **/
idx = loc(x >= 35.855431998);
TP = TrapIntegral(x[idx],y[idx]);
print tp;

quit;

I would appreciate any hint you can give me or whether you think it is even possible to conduct.

Kind regards,
Tim