compute vprgey6=pregey6.
compute vprgey7=pregey7.
compute vprgey8=pregey8.
compute vprgey9=pregey9.
compute vprgey10=pregey10.
compute vprgey11=pregey11.
compute vprgey12=pregey12.
compute vprgey13=pregey13.
compute vprgey14=pregey14.
compute vprgey15=pregey15.
compute vprgey16=pregey16.
compute vprgey17=pregey17.
compute vprgey18=pregey18.
compute vprgey19=pregey19.
compute vprgey20=pregey20.
compute vprgey21=pregey21.
compute vprgey22=pregey22.
compute vprgey23=pregey23.
compute vprgey24=pregey24.
compute vprgey25=pregey25.
compute vprgey26=pregey26.
compute vprgey27=pregey27.
compute vprgey28=pregey28.
compute vprgey29=pregey29.
compute vprgey30=pregey30.
compute vprgey31=pregey31.
compute vprgey32=pregey32.
compute vprgey33=pregey33.
compute vprgey34=pregey34.
compute vprgey35=pregey35.
compute vprgey36=pregey36.
compute vprgey37=pregey37.
compute vprgey38=pregey38.
compute vprgey39=pregey39.
compute vprgey40=pregey40.
* Use variable totbaby to calculate number of babies carried in total, by checking each
* of the 40 possible slots for any date or outcome.
compute totbaby=0.
format totbaby(f1.0).
loop #i=1 to 40.
If (not(sysmis(vprega(#i))) or not(sysmis(vprgey(#i))) or not(sysmis(vprgem(#i))) or
not(sysmis(vprged(#i))))totbaby=totbaby+1.
end loop.
* Initialise variable 'noyrflag' to log cases where any outcome has a year '9999'.
* These cases must be excluded from the automatic re-ordering,and scrutinised manually.
compute noyrflag=0.
format noyrflag(f1.0).
compute pre91flg=0.
format pre91flg(f1.0).
* Construct date-of-birth variables which can be measured ordinally and subtracted from each
other,
* using yrmoda function, which produces number of days elapsed since 15/10/1582.
* Flag up cases where year=9999, or prega (outcome)=9 or 8, for manual scrutiny.