Here is an approach to replace your existing parity value with a new one. This is a different dataset Have than that provided by
@Ksharp.
data have;
informat date mmddyy10.;
format data mmddyy10.;
input id Parity Date;
cards;
5
.
5/1/2005
5
2
9/11/2007
5
3
1/1/2009
731
.
2/5/2010
731
1
7/6/2012
5555
2
5/1/2005
5555
.
9/11/2007
5555
3
1/1/2009
;
run;
proc sort data=have;
by id date;
run;
data want;
set have;
by id;
retain newparity;
if first.id then do;
if parity>0 then newparity =Parity;
else Newparity=1;
end;
else newparity=newparity+1;
run;
as I show one mother having an "accurate" non-missing non-zero initial parity.
... View more