data have;
input ID Appt $ Year Month;
cards;
1 A 2014 10
1 A 2014 11
1 A 2014 12
1 B 2015 1
1 B 2015 2
1 B 2015 3
1 B 2015 4
2 A 2014 10
2 A 2014 11
2 A 2014 12
2 A 2015 1
2 A 2015 2
2 B 2016 1
2 B 2016 2
2 B 2016 3
2 B 2016 4
;
data month;
do m=1 to 12;
output;
end;
run;
proc sql;
create table temp as
select a.*,b.month,missing(b.month) as group
from (select * from (select distinct ID,Appt,Year from have),(select m from month)) as a
left join
(select * from have) as b
on a.ID=b.ID and a.Appt=b.Appt and a.Year=b.Year and a.m=b.month
order by 1,2,3,4;
quit;
data temp1;
set temp;
by ID Appt group notsorted;
if first.group then count=0;
count+1;
if not missing(month);
drop m group;
run;
proc sql;
create table want as
select *
from temp1
where catx(' ',id,Appt) in
(select catx(' ',id,Appt) from temp1 group by id having count=max(count));
quit;
... View more