proc sql;
create table endpoint as
select name, min(catx('-',year,qtr)) as start, max(catx('-',year,qtr)) as stop
from test
group by 1;
quit;
proc sort data=test;
by name year qtr;
run;
proc sql;
create table allclass1 as
select distinct name, year
from test;
quit;
data allclass2;
set allclass1(keep=name year);
do qtr=1 to 4;
output;
end;
run;
proc sort data=allclass2;
by name year qtr;
run;
data allclass;
merge test allclass2;
by name year qtr;
length _ins _sex $40;
retain _ins _sex;
if first.name then do;_ins=' ';_sex=' ';end;
if ^missing(institution) then do;
_ins=institution;
_sex=sex;
end;
else do;
institution=_ins;
sex=_sex;
end;
time=catx('-',year,qtr);
drop _ins _sex;
run;
data wanted;
set allclass;
do i=1 to nobs;
set endpoint(rename=(name=name1)) point=i nobs=nobs;
if name=name1 and time>=start and time<=stop then output;
end;
drop name1 time start stop;
run;