Data LboundNe;

*******************************************************************

A SAS program to find by bisection a lower 1-LBalpha confidence

bound for Ne, the number of population items in error.  Population

size Npop, SRS size nsamp, ne = number of sample items in error. 

The returned confidence bound is called NeL.

******************************************************************;

** fill in these values each time;

Npop=;

nsamp=;

ne=;

LBalpha=0.10;

*************************************;

if ne = 0 then NeL=0;

      else do;

            Na = ne;

            Pa = 0;

            if Pa GE LBalpha then NeL=ne;

            else do;

                  Nb = Npop;

                  Pb = 1;

                  do while ((Nb - Na) > 1);

                        Nnew = floor((Nb + Na)/2);

                        Pnew = (1 - probhypr(Npop, Nnew, nsamp, ne-1));

                        if Pnew GE LBalpha then do;

                          Nb = Nnew;

                          Pb = Pnew;

                        end;

                        else do;

                          Na = Nnew;

                          Pa = Pnew;

                        end;

                  end;

                  if Pa GE LBalpha then NeL=Na;

                  else NeL=Nb;

            end;

      end;

output;

proc print;

var Npop nsamp ne LBalpha NeL;

run;