something like this in SQL by doing union all for each scenario mentioned.
proc sql;
create table want as
/*scenario 1*/
select id, result from have
group by 1
having count(id) =1
union all
/*scenario 2*/
select id, min(result) as result from
( select id, result from have
group by 1
having count(id) gt 1
and min(result) >= 30)a
group by id
union all
/*scenario 3*/
select id, max(result) as result from
( select id, result from have
group by 1
having count(id) gt 1
and min(result) < 30)a
group by id
order by id;
quit;
;
on date column as min or max value
proc sql; create table want as /*scenario 1*/ select id, result, date format=date9. from have group by 1 having count(id) =1 union all /*scenario 2*/ select id, result, min(date) as date from ( select id, result , date from have group by 1 having count(id) gt 1 and min(result) >= 30)a group by id union all /*scenario 3*/ select id,result, max(date) as date from ( select id, result, date from have group by 1 having count(id) gt 1 and min(result) < 30)a group by id order by id; quit;
... View more