The problem could be with the way you read your data. Compare the results with and without the infile statement in
data closenessRanks;
input age rank;
datalines;
85 0
84 1
86 2
83 3
87 4
88 5
89 6
90 7
91 8
92 9
93 10
94 11
95 12
96 13
97 14
98 15
99 16
;
data have;
infile datalines missover;
input id visit age score;
datalines;
1 1 80 30
1 2 85 28
1 3 86 25
2 1 84 25
2 2 87 24
3 1 90 28
3 2 95 28
4 1 79 88
4 2 80 99
5 1 80
5 2 85 28
5 3 86 25
;
proc sql;
create table want as
select a.*,
case when coalesce(rank, -1)=min(rank) then score else . end as newScore
from
have as a left join
closenessRanks as b on a.age=b.age
group by id
order by id, visit;
select * from want;
quit;
... View more