here is a sample code which would do good with the example, but you will need to modify it when there are more than 2 offence_date. proc sql; create table admit as select * from ( select distinct a.id,admit_date format mmddyy10.,admit_date as offence_date format mmddyy10.,sex from ( select id,offence_date format mmddyy10., min(offence_date) as min format mmddyy10., case when count(id) =1 then today() else max(offence_date) end as max format mmddyy10., sex from offenders group by id ) a left join hospital b on a.id= b.id and admit_date between min and max ) where admit_date is not null order by id,offence_date ; quit; proc sort data=offenders; by id offence_date; run; data fin; merge offenders admit; by id offence_date; if offence_date= admit_date then call missing(offence_date); run;
... View more