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;
@schatterjee wrote:
Hi Reeza,
I redid the analyses, and that error was resolved. This time I received a warning "Convergence was not attained in 25 iterations". Also for the final output, all the fields (parameter estimate, std error, 95% CI, Chi-Sq, Pr>Chi-sq, HR, 95% CI of HR) are blank. Is it because convergence was not attained?
Satabdi
Yes, but that's likely due to a data issue. Check that you have enough data, and that you don't have 0 cells in your categorical data.
Hi Reeza,
I received the error at the proc phreg step.
Thanks,
Satabdi
Hi Reeza,
I redid the analyses, and that error was resolved. This time I received a warning "Convergence was not attained in 25 iterations". Also for the final output, all the fields (parameter estimate, std error, 95% CI, Chi-Sq, Pr>Chi-sq, HR, 95% CI of HR) are blank. Is it because convergence was not attained?
Satabdi
@schatterjee wrote:
Hi Reeza,
I redid the analyses, and that error was resolved. This time I received a warning "Convergence was not attained in 25 iterations". Also for the final output, all the fields (parameter estimate, std error, 95% CI, Chi-Sq, Pr>Chi-sq, HR, 95% CI of HR) are blank. Is it because convergence was not attained?
Satabdi
Yes, but that's likely due to a data issue. Check that you have enough data, and that you don't have 0 cells in your categorical data.
@schatterjee wrote:
Hi Reeza,
I received the error at the proc phreg step.
Thanks,
Satabdi
Fairly clear error:
ERROR: Data set PERM.BOOTSAMPLEPSMATCH1 is not sorted in ascending sequence.
In
PROC PHREG DATA=PERM.BOOTSAMPLEPSMATCH1; BY REPLICATE;<= NOT sorted properly here CLASS EXPOSURE /PARAM=REF REF=FIRST; MODEL TIMETOEVENT * CENSOR(0) = EXPOSURE /RL; STRATA MATCHTO; TITLE "PROPENSITY-SCORE MATCHED BOOTSTRAPPED COX MODEL"; RUN;
So sort the data set BY REPLICATE prior to the Proc Phreg.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.