Hello members, I am trying to implement bootstrapping for generating propensity scores, perform PS matching (GREEDY 5→1 algorithm) and then obtain bootstrapped estimates from the final Cox regression. The final step is not executed and I am receiving the following error message: "ERROR: Data set PERM.BOOTSAMPLEPSMATCH1 is not sorted in ascending sequence. The current BY group has Sample Replicate Number = 98 and the next BY group has Sample Replicate Number = 3." Please see my editor below. Your help on this will be highly appreciated! %let rep = 100;
proc surveyselect data= cohort out=BOOTSAMPLE
seed = 1347 method = urs
samprate = 1 outhits rep = &rep;
run;
PROC LOGISTIC DATA=BOOTSAMPLE DESCENDING;
BY REPLICATE;
CLASS EXPOSURE AGE SEX CATVAR1 CATVAR2 CATVARN /PARAM=REF REF=FIRST;
MODEL NON_SEL = CATVAR1 CATVAR2 CATVARN CONTVAR1;
OUTPUT OUT= BOOTSAMPLEPS(DROP=_LEVEL_) PRED=PROB XBETA=LOGIT;
RUN;
/*============================================================*/
/*PS MATCHING*/
/*============================================================*/
%MACRO GREEDMTCH (Lib=, Dataset=, depend=, matches= );
%macro sortcc;
proc sort data = tctrl out = &lib..scontrol;
by prob randnum;
run;
proc sort data = tcases out = &lib..scase;
by prob ;
run;
%mend sortcc;
%macro initcc(digits);
data tcases(drop=cprob)
tctrl(drop=aprob);
set &lib..&dataset.;
if &depend. = 0 then do;
cprob = round(prob,&digits.);
cmatch = 0;
randnum = ranuni(1234567);
output tctrl;
end;
else if &depend. = 1 then do;
cmatch = 0;
aprob = round(prob,&digits.);
output tcases;
end;
run;
%sortcc;
%mend initcc;
%macro match(matched,digits);
data &lib..&matched.(drop = cmatch randnum aprob cprob start oldi
curctr1 matched);
set &lib..scase;
curob + 1;
matchto = curob;
if curob = 1 then do;
start = 1;
oldi = 1;
end;
do i = start to n;
set &lib..scontrol point = i nobs = n;
if i > n then goto startovr;
if _error_ = 1 then abort;
curctr1 = i;
if aprob = cprob then do;
cmatch = 1;
output &lib..&matched.;
matched = curctr1;
goto found;
end;
else if cprob > aprob then
goto nextcase;
startovr:
if i > n then goto nextcase;
end;
nextcase:
if cmatch = 0 then start = oldi;
found:
if cmatch = 1 then do;
oldi = matched + 1;
start = matched + 1;
set &lib..scase point = curob;
output &lib..&matched.;
end;
retain oldi start;
if _Error_=1 then _Error_=0;
run;
proc sort data = &lib..scase out = sumcase;
by ID;
run;
proc sort data = &lib..scontrol out = sumcontrol;
by ID;
run;
proc sort data = &lib..&matched. out = smatched(keep=BENE_ID matchto);
by ID;
run;
data tcases(drop=matchto);
merge sumcase(in = in1)
smatched;
by ID;
if in1 and matchto = .;
cmatch = 0;
aprob = round(prob,&digits.);
run;
data tctrl(drop=matchto);
merge sumcontrol(in = in1)
smatched;
by ID;
if in1 and matchto = .;
cmatch = 0;
cprob = round(prob,&digits.);
run;
%sortcc;
%mend match;
%initcc(.000001);
%match(match5,.00001);
%match(match4,.0001);
%match(match3,.001);
%match(match2,.01);
%match(match1,.1);
data &lib..&matches.;
set &lib..match5(in = a)
&lib..match4(in = b)
&lib..match3(in = c)
&lib..match2(in = d)
&lib..match1(in = e);
if a then matchto = matchto + 1000;
if b then matchto = matchto + 100000;
if c then matchto = matchto + 10000000;
if d then matchto = matchto + 1000000000;
if e then matchto = matchto + 100000000000;
run;
proc sort data = &lib..&matches. out = &lib..s&matches.;
by &depend.;
run;
%mend greedmtch;
%GREEDMTCH( Lib=PERM, Dataset=BOOTSAMPLEPS, depend=EXPOSURE, matches=BOOTSAMPLEPSMATCH);
PROC SORT DATA=PERM.BOOTSAMPLEPSMATCH OUT=PERM.BOOTSAMPLEPSMATCH1;
BY ID REPLICATE;
RUN;
PROC PHREG DATA=PERM.BOOTSAMPLEPSMATCH1;
BY REPLICATE;
CLASS EXPOSURE /PARAM=REF REF=FIRST;
MODEL TIMETOEVENT * CENSOR(0) = EXPOSURE /RL;
STRATA MATCHTO;
TITLE "PROPENSITY-SCORE MATCHED BOOTSTRAPPED COX MODEL";
RUN;
... View more