Modified data just to keep one min and max. I think this should work.
data have ;
input id $ sp_num $ type $ date_1 yymmdd8.;
format date_1 date9. ;
datalines;
101 a01 p 20160102
101 a01 b 20160103
101 a01 b 20160105
102 b02 b 20160104
102 b02 b 20160105
103 c03 p 20160106
103 c03 b 20160107
103 c03 p 20160108
104 d04 p 20160102
104 d04 b 20160104
;
run;
/*picking up min and max records*/
proc sql;
create table inter as
select *, monotonic() as rnum from want a
where date_1=(select max(date_1) as max_d
from want b
where a.id =b.id
group by id)
or date_1=(select min(date_1) as max_d
from want b
where a.id =b.id
group by id)
order by id, date_1;
quit;
/* picking up the rows which have change in type you can extent it to others if you want*/
proc sql;
create table want as
select id, sp_num, type, date_1 from inter a
inner join
inter b
on a.id = b.id
and a.type <> b.type
where (a.rnum+1 =b.rnum
or b.rnum +1 =a.rnum);
quit;
... View more