Script searching data in a kinship matrix

#1
Hello everybody,
in a case-control study I have sampled cases stratifying for sex
(0,1) and age (=62y). I need to sample a group of controls with the
same characteristics (which I have already done) plus
one more: the level of relatedness. In particular I need that controls are as least as possible
related to cases, for example each control should have a kinship coefficient
less than 0.0156 (i.e. 1/64 as for second cousins) with its matched case. In
the example data I attach, there are the sampled cases [20 cases (where
disease=1): 5 subjects for each strata] and 200 possible controls
(disease=0) I have already sampled stratifying for age and sex (50 subjects
per strata).
What I do not know is how to solve the relatedness problem. I have already
computed the kinship coefficients matrix of the extended pedigree to whom
the cases and controls in the example data belong. Indeed I could retrieve only 190 of the 220 subjects of the data example, so that the relative kinship matrix is a 190X190). I also attach this kinship matrix.
I need a script that looks down such kinship matrix searching
for controls satisfying the relatedness condition and that adds this
information to my original data set.
The information could be reported in many ways (the simplest to obtain it):
For example, the script may add to the original data set as many columns as
the maximum number of controls satisfying the relatedness condition for
their matched cases. In particular in correspondence of each case (rows for
which disease=1) the new columns should return the ID of the matched
control satisfying the condition: case-control kinship< 0.0156 ; otherwise a
zero (if condition is not satisfied), and finally a missing value (if the
subject's ID is not in the kinship matrix).
One other alternative may be that the script adds to the original data set
as many rows as the maximum number of controls satisfying the relatedness
condition for their matched cases. Such new rows (for each matched case)
may report the control's ID in the ID column, missing values in the disease,
age and sex columns, and the ID of the matched case in a new column.
Whatever alternative solution is welcome!
Does anybody can help me?