BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
schatterjee
Calcite | Level 5

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;  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@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.

View solution in original post

12 REPLIES 12
Reeza
Super User
PROC PSMATCH will do greedy matching for you.
schatterjee
Calcite | Level 5
Thanks Reeza! Can you suggest a way to resolve the error on bootstrapping in the final step on regression?
Reeza
Super User
Sorry, I have no idea what the error is. I can't run your code (no data), there are no comments to let me know what you thought was happening and you didn't include the log or error.
Reeza
Super User
Sorry, you did include the error but didn't indicate which step generates it.
schatterjee
Calcite | Level 5

Hi Reeza,

I received the error at the proc phreg step.

 

Thanks,

Satabdi

Reeza
Super User
Why did you sort by ID? Is that needed? The error is because the BY statement is different between the sort and the PROC PHREG.
schatterjee
Calcite | Level 5
Thanks so much Reeza! Let me try without id and see what I get.
schatterjee
Calcite | Level 5

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

 

Reeza
Super User

@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
Calcite | Level 5
Ok thank you so much for your help!
ballardw
Super User

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 1287 views
  • 0 likes
  • 3 in conversation