interpolating from 2 numbers is not too difficult to manage, notice that the one- missing end scenario is also included.
data raw;
input cow_ID day milk_yield max_length ;
datalines;
1 1 21.6 335
1 2 21.6 335
1 4 21.6 335
1 335 16.8 335
3 3 18.4 410
3 5 20.1 410
3 410 10.8 415
;
run;
data want;
set raw;
by cow_id;
set raw(firstobs=2 keep=day milk_yield rename=(day=_day milk_yield=_mk)) raw(obs=1 drop=_all_);
if first.cow_id and day>1 then do;
_fday=day;
do day=1 by 1 while (day<_fday);
output;
end;
end;
if not last.cow_id then do;
do _n_=1 by 1 to _day-day;
if _n_=1 then do;
_mk1=milk_yield;
_day1=day;
end;
milk_yield=_mk1+(day-_day1)*((_mk-_mk1)/(_day-_day1));
output;
day=day+1;
end;
end;
else do;
do while (day<=max_length);
output;
day=day+1;
end;
end;
drop _:;;
run;
... View more