Assuming I understand your question.
data have;
input ID
Visitdate : $20.
Indexdate : $20.
Previousvisitslabel
Afterindexlabel ;
cards;
1
.
Jun7,2005
.
.
2
Jan3,1999
Apr8,1999
1
0
3
Jan3,1999
Jan1,1998
0
1
4
Oct7,2002
Sept10,2001
0
1
4
Jun1,2001
Sep10,2001
1
0
;
run;
proc sql;
create table A as
select id,' ' as Visitdate,Indexdate,. as Previousvisitslabel from have
where id not in (select id from have where Previousvisitslabel=1)
union all
select ID,
Visitdate ,
Indexdate,
Previousvisitslabel from have where Previousvisitslabel=1
order by id ;
create table B as
select id,' ' as Visitdate,Indexdate,. as Afterindexlabel from have
where id not in (select id from have where Afterindexlabel=1)
union all
select ID,
Visitdate ,
Indexdate,
Afterindexlabel from have where Afterindexlabel=1
order by id ;
quit;