You didn't post the output you need according to your sample data yet ? If I understood what you want. data Data1 ;
infile datalines dlm=",";
informat interviewdt date9.;
format interviewdt date9.;
input study_id qnum interviewdt;
datalines ;
1,1,14FEB2008
1,2,12FEB2009
1,3,01MAR2010
2,1,04SEP2012
3,1,19MAR2008
3,2,12OCT2010
3,3,17NOV2011
;
run;
data Data2 ;
infile datalines dlm=",";
informat medstartdate date9.;
format medstartdate date9.;
input study_id medstartdate atc_code $ drug_class $;
datalines ;
1,01MAY1996,ABC,
1,01NOV1996,CBA,A
1,01NOV1996,CBB,B
1,01NOV1996,CBC,A
2,31MAR1999,ABC,
2,01JUN1999,CBD,C
2,01JUN1999,CBE,A
2,01MAY2003,ABC,
3,17FEB1999,CBA,A
3,17FEB1999,CBA,A
3,17FEB1999,CBB,B
3,01MAR2000,ABC,
;
run ;
proc sql;
create table want as
select a.*,case
when exists(select * from data2 where study_id=a.study_id and drug_class is not missing and medstartdate lt a.interviewdt) then 'YES'
else 'NO '
end as MedStartDtDiff
from data1 as a
where qnum=1;
quit;
Xia Keshan Message was edited by: xia keshan Fix a problem .
... View more