data test1;
set have;
array a admin_date1-admin_date6;
array b admin_date1-admin_date6 ;
array x $ type1-type6;
array y $ type1-type6;
array v(5,6) $10 a1b1-a1b6 a2b1-a2b6 a3b1-a3b6 a4b1-a4b6 a5b1-a5b6;
do i=1 to 5;
do j=i+1 to 6;
/* case 1: If both types = P, the difference between the dates must be 17 or more.
case 2: All other combinations must be 24 or more days apart*/
if (x(i)='P' and y(j)='P' and b(j)-a(i)>=17)
or ((x(i)^='P' or y(j)^='P') and b(j)-a(i)>=24) then
do;
v(i,j)='Y'; output;
end;
end;
end;
run;
data want;
set test1;
format admin_date_1-admin_date_6 mmddyy10.;
array a admin_date1-admin_date6;
array b admin_date_1-admin_date_6 ;
array x $ type1-type6;
array y $ type_1-type_6;
array v(5,6) $10 a1b1-a1b6 a2b1-a2b6 a3b1-a3b6 a4b1-a4b6 a5b1-a5b6;
do n=1 to 5;
do m=n+1 to 6;
if v(n,m)='Y' then do; b(n)=a(n); y(m)=x(m); end;
end;
end;
keep person i j admin_date_1-admin_date_6 type_1-type_6;
run;
... View more