This is clunky but what I figured out on my own and works.
data have; input person $ admin_date_1 : ?? mmddyy10. admin_date_2 : ??mmddyy10. admin_date_3 : ?? mmddyy10. admin_date_4 : ?? mmddyy10. admin_date_5 : ?? mmddyy10. admin_date_6 : ?? mmddyy10. type_1 $ type_2 $ type_3 $ type_4 $ type_5 $ type_6 $; format admin_date_1 mmddyy10. admin_date_2 mmddyy10. admin_date_3 mmddyy10. admin_date_4 mmddyy10. admin_date_5 mmddyy10. admin_date_6 mmddyy10.; datalines; JohnDoe 01/12/2021 01/13/2021 01/19/2021 01/30/2021 02/01/2021 02/15/2021 M P M P P J ; run; *in order for this to work correctly, you have to order the DAYS_BT_DOSE fields in ascending order like below in the format;
%macro test;
data want (keep=person new:);
set have;
format L_DAYS_BT_DOSE_1_2 L_DAYS_BT_DOSE_1_3 L_DAYS_BT_DOSE_2_3 L_DAYS_BT_DOSE_1_4 L_DAYS_BT_DOSE_2_4
L_DAYS_BT_DOSE_3_4 L_DAYS_BT_DOSE_1_5 L_DAYS_BT_DOSE_2_5 L_DAYS_BT_DOSE_3_5 L_DAYS_BT_DOSE_4_5 L_DAYS_BT_DOSE_1_6 L_DAYS_BT_DOSE_2_6
L_DAYS_BT_DOSE_3_6 L_DAYS_BT_DOSE_4_6 L_DAYS_BT_DOSE_5_6
F_DAYS_BT_DOSE_1_2 F_DAYS_BT_DOSE_1_3 F_DAYS_BT_DOSE_2_3 F_DAYS_BT_DOSE_1_4 F_DAYS_BT_DOSE_2_4
F_DAYS_BT_DOSE_3_4 F_DAYS_BT_DOSE_1_5 F_DAYS_BT_DOSE_2_5 F_DAYS_BT_DOSE_3_5 F_DAYS_BT_DOSE_4_5 F_DAYS_BT_DOSE_1_6 F_DAYS_BT_DOSE_2_6
F_DAYS_BT_DOSE_3_6 F_DAYS_BT_DOSE_4_6 F_DAYS_BT_DOSE_5_6 NEW_ADMIN_DT_1 NEW_ADMIN_DT_2 MMDDYY10.
;
%do i = 1 %to 5;
%let nxt = %eval(&i. + 1);
%do b=&nxt %to 6;
if TYPE_&i = 'P' and TYPE_&b = 'P' and intck('day',ADMIN_DATE_&i,ADMIN_DATE_&b) ge 17
then do;
L_DAYS_BT_DOSE_&i._&b = ADMIN_DATE_&b;
F_DAYS_BT_DOSE_&i._&b = ADMIN_DATE_&i;
end;
else if TYPE_&i in ('P','M','J') and TYPE_&b in ('P','M','J') and intck('day',ADMIN_DATE_&i,ADMIN_DATE_&b) ge 24
then do;
L_DAYS_BT_DOSE_&i._&b = ADMIN_DATE_&b;
F_DAYS_BT_DOSE_&i._&b = ADMIN_DATE_&i;
end;
%end;
%end;
NEW_ADMIN_DT_1 = COALESCE(of F_DAYS_BT_DOSE:);
NEW_ADMIN_DT_2 = COALESCE(of L_DAYS_BT_DOSE:);
run;
%mend test;
*execute macro;
%test;
... View more