Hi @Emma2021 @Reeza 's recommendation is spot on and very wise. Right, I am just posting for fun and to get my fingers back into some practice. I'd still suggest to go with Reeza's suggestion or use a DB specific SQL making use of the PARTIITON BY() option, enabling the use of min from each partition.
Anyways, for fun-
data have;
input id day flag;
cards;
1 1 .
1 1 2
2 4 2
2 4 .
2 5 .
3 3 2
3 3 .
3 3 8
;
proc sql;
create table want as
select a.id,a.day,coalesce(a.flag,b.flag) as flag
from have a
left join
(select *
from (select *,monotonic() as n from have)
group by id, day
having min(case when flag>. then n else . end)=n) b
on a.id=b.id and a.day=b.day;
quit;
... View more