Here's a simple SAS datastep. You can adjust it to use VNAME() to define relation (depending on how your other variables are named); for example,
relation = vname(DOBs[_t]);
Then use SUBSTR or whatever to shorten it to the proper text. Other than that it should be sufficiently flexible to handle any number of relations in the initial HAVE dataset.
data want;
set have;
array DOBs SPOUSEDOB FCHILDDOB SCHILDDOB;
do _t = 1 to dim(DOBs);
if DOBs[_t] ne '01JAN1900'd then do;
relation=ifc(_t=1,'Spouse','Child'); *this could also be done using VNAME() to be more flexible;
DOB=DOBs[_t];
output;
end;
end;
keep relation DOB ChangeDate U_ID;
format DOB Changedate Date9.;
run;
proc sort data=want;
by u_id descending relation dob changedate;
run;
data final;
set want;
by u_id descending relation dob changedate;
if first.dob;
run;
Then to process it to select only people born as of a certain date you can use the query fthiella posted if you prefer to use SQL, or you can filter in a SAS proc, like:
proc means data=final;
where dob le '01JAN2006'd;
class relation;
var (whatever);
run;
Or use ChangeDate if that is what you want to filter on rather than actual DOB.