I took a guess at what output you wanted but here is a solution. data have; infile cards dsd; informat pid $3. test_date dz_date mmddyy10.; format pid $3. test_date dz_date mmddyy10.; input PID test_date dz_date; cards; 101,4/1/2013, 101,8/22/2013, 101,11/10/2013, 101,,6/18/2013 102,2/11/2013, 102,8/14/2013, 102,12/23/2013, 102,,2/4/2014 203,6/21/2013, 203,,2/5/2013 ; proc sort data=have;by pid test_date dz_date; data prep; set have; by pid; retain date; if not missing(dz_date) then date = dz_date; test = abs(intck('month',test_date,date)); drop date; run; proc sql; create table want as select distinct pid, case when min_test < 4 then '1' else '0' end as BiVar from( select *,min(test) as min_test from prep group by pid);
... View more