Instead of using %GOTO, wrap the two blocks in mutually exclusive %DO-%END:
%macro link;
%do i = 1 %to 9;
%if &i ne 5 and &i ne 6
%then %do;
proc sql noprint;
create table link_dth&i as
select a.DTHID&i, a.year as DTH_YEAR, a.UID4S&i as DTH_UID4S&i, b.UID4S&i as PMP_UID4S&i,
b.SEQ as SEQ, b.year as PMP_YEAR
from in.cleanall_test_UID4S&i as a, pmp.cleanall_test_UID4S&i as b
where a.UID4S&i=b.UID4S&i
;
quit;
%end;
%else %do;
proc sql noprint; /*Link PMP with SPARCS 5,6*/
create table link_dth&i as
select a.DTHID&i, a.year as DTH_YEAR, a.UID4S&i as DTH_UID4S&i, a.gender_DTH as DTH_GENDER,
b.UID4S&i as PMP_UID4S&i, b.SEQ as SEQ,
b.year as PMP_YEAR, b.gender_PMP as PMP_GENDER
from in.cleanall_test_UID4S&i as a, pmp.cleanall_test_UID4S&i as b
where a.UID4S&i=b.UID4S&i and a.gender_DTH=b.gender_PMP
;
quit;
%end;
%end;
%mend;
... View more