compute xabsmn(#i)=vabsmn(key40(#i)).
compute xgramm(#i)=vgramm(key40(#i)).
compute xprgey(#i)=vprgey(key40(#i)).
compute xabsyr(#i)=vabsyr(key40(#i)).
compute xprege(#i)=vprege(key40(#i)).
compute xpregi(#i)=vpregi(key40(#i)).
end if.
end loop.
Loop #i=1 to 8.
Do if (keypreg(#i) ne 0).
compute xpregj(#i)=vpregj(keypreg(#i)).
compute xcg1prg(#i)=vcg1prg(keypreg(#i)).
compute xcg2prg(#i)=vcg2prg(keypreg(#i)).
compute xcg3prg(#i)=vcg3prg(keypreg(#i)).
compute xcpregb(#i)=vcpregb(keypreg(#i)).
compute xpregk(#i)=vpregk(keypreg(#i)).
compute xpregkw(#i)=vpregkw(keypreg(#i)).
compute xpregl(#i)=vpregl(keypreg(#i)).
end if.
end loop.
end if.
* Compute new value of morepreg(1-8) from knowledge of whether there are any babies in
the next-most recent pregnancy slot.
Do if (changed=1 or changed=2).
loop #i=1 to 8.
compute xmorprg(#i)=2.
end loop.
loop #i=1 to 7.
If (xpregnu(#i+1) ge 1)xmorprg(#i)=1.
end loop.
* Copy all the data from the x-prefix vectors to the original variables, overwriting data in wrong
birthslots.
compute pregnum =xpregnu1.
compute pregnum2=xpregnu2.
compute pregnum3=xpregnu3.
compute pregnum4=xpregnu4.
compute pregnum5=xpregnu5.
compute pregnum6=xpregnu6.
compute pregnum7=xpregnu7.
compute pregnum8=xpregnu8.
compute pregj =xpregj1.
compute pregj2=xpregj2.
compute pregj3=xpregj3.
compute pregj4=xpregj4.
compute pregj5=xpregj5.
compute pregj6=xpregj6.
compute pregj7=xpregj7.
compute pregj8=xpregj8.