My solution assumes input data sorted by ID, YEAR and involves using two arrays. One auxiliary (temporary) array which will store the correct obs, and one associated array with the N1-N4 variables. Then you just have to "travel" through the group, check every obs. and store the correct one into the auxiliary array. At the end of the group, just output the auxiliary array.
Since there is only 4 variables to preserve, this could be also done with 4 auxiliary variables. But the array solution provides a "cleaner" coding.
[pre]
data NEWTABLE;
set OLDTABLE;
by ID YEAR;
drop I;
array _NX {4} _temporary_; * auxiliary array;
array NX {4} N1 - N4; * associated array;
* init aux array;
if first.YEAR then _NX{1}=.;
* check rule and store into auxiliary array;
if (NX{1} eq 1 and (_NX{1} ne 1 or NX{2} gt _NX{2})) or
(NX(1) eq 0 and _NX{1} ne 1 and NX{3} gt _NX{3}) then
do I=1 to 4;
_NX{I}=NX{I};
end;
if last.YEAR; * last element in group;
do i=1 to 4;
NX{i}=_NX{i};
end; * restore data from auxiliary array;
run;
[/pre]
Cheers from Portugal.
Daniel Santos @
www.cgd.pt