- data b;
- set a;
- by id export notsorted;
- if first.id then sort=0;
- if first.export & export=1 then sort+1;
- run;
- data c;
- set b;
- by id sort;
- if (first.sort & export=0) | (last.sort & export=1) then delete;
- run;
- proc sql noprint;
- create table want as
- select distinct id,sum(export) as suv,min(year) as startyear from c
- group by id,sort having count(*)>1 & min(export)=0 order by id,startyear;
- quit;