* Impute day and month as 15, 6 respectively if not available, as long as year has been
entered sensibly.
* Impute date 30th Sept 2000 for any ongoing pregnancies.
loop #i=1 to 40.
Do if(vprgey(#i) ge 1900 and vprgem(#i) ge 1 and vprgem(#i) le 12 and vprged(#i) ge 1 and
vprged(#i) le 31).
compute birdat(#i)=yrmoda(vprgey(#i),vprgem(#i),vprged(#i)).
compute compdt(#i)=1000000*vprged(#i)+10000*vprgem(#i)+vprgey(#i).
end if.
Do if(vprgey(#i)=9999 or vprgey(#i)=9998 or vprega(#i)=9 or vprega(#i)=8).
compute noyrflag=1.
compute compdt(#i)=99999999.
end if.
Do if(vprgey(#i) ne 9999 and vprgey(#i) ne 9998 and (vprged(#i) ne 99) and (vprgem(#i)=99
or sysmis(vprgem(#i)))).
compute birdat(#i)=yrmoda(vprgey(#i),6,vprged(#i)).
compute compdt(#i)=1000000*vprged(#i)+60000+vprgey(#i).
end if.
Do if(vprgey(#i) ne 9999 and vprgey(#i) ne 9998 and (vprged(#i)=99 or (vprged(#i)=98) or
sysmis(vprged(#i))) and (vprgem(#i)=99 or sysmis(vprgem(#i)))).
compute birdat(#i)=yrmoda(vprgey(#i),6,15).
compute compdt(#i)=15060000+vprgey(#i).
end if.
Do if(vprgey(#i) ne 9999 and vprgey(#i) ne 9998 and vprgem(#i) ne 99 and (vprged(#i)=99 or
vprged(#i)=98 or sysmis(vprged(#i)))).
compute birdat(#i)=yrmoda(vprgey(#i),vprgem(#i),15).
compute compdt(#i)=15000000+10000*vprgem(#i)+vprgey(#i).
end if.
Do if(vprega(#i)=5).
compute birdat(#i)=yrmoda(2000,9,30).
compute compdt(#i)=30092000.
end if.
end loop.
* Flag up all cases where birth dates are out of order.
compute ordrflag=0.
format ordrflag (f1.0).
loop #i=1 to 39.
loop #j=1 to #i.
if (birdat(1+#i)>birdat(#j))ordrflag=1.
end loop.
end loop.
* Flag up all cases where outcomes more than nine months apart are bunched as though part
of the same pregnancy.
compute bunched=0.
format bunched (f1.0).