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

Hi,

 

I am running a Cox proportional hazard model evaluating the association of a binary predictor x on outcome Y. My objective is to apply varying sensitivity/specificity definitions of x to account for potential misclassification.

To do this, I would like to randomly select a pre-specified sample size from the population and change their value for x. I would like to obtain a hazard ratio in this hypothetical population. I would then like to repeat this process several hundred/thousand times to obtain an average.

 

Below is the code that will accomplish this task once. I need help with a macro to have this process repeated several hundred/thousand times and obtain an average from those simulations. Any help is very much appreciated!

 

data new;                                                                                     

set data_original;                                                 

x_new=x;

ran=ranuni(); /* random number between 0 and 1 */

if ran<=0.1 and x=0 then x_new=1; /* if random number <= 0.1 (misclassification probability) and original x. = no, then new x. = yes */

run;

 

proc phreg data = new ….

                ….

                ….

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I would do this simulation like this :

 

data new;                                                                                     
call streaminit(869768);
set data_original;                  
do rep = 1 to 1000;
        /* 10 % of the x = 0 are changed to x = 1 */
	if  rand("BERNOULLI", 0.1)  and x = 0 then x_new = 1;
	else x_new = x;
	output;
	end;
run;

proc sort data=new; by rep; run;

proc phreg data = new outest = newEstimates ...;
by rep;
...;
PG

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

I would do this simulation like this :

 

data new;                                                                                     
call streaminit(869768);
set data_original;                  
do rep = 1 to 1000;
        /* 10 % of the x = 0 are changed to x = 1 */
	if  rand("BERNOULLI", 0.1)  and x = 0 then x_new = 1;
	else x_new = x;
	output;
	end;
run;

proc sort data=new; by rep; run;

proc phreg data = new outest = newEstimates ...;
by rep;
...;
PG
mnayan
Calcite | Level 5

This worked well, thank you so much!

I have one question regarding the confidence intervals of the simulation models. Have these taken into account the repeated nature of the data or are they inappropriately narrow and need further adjustment? If the latter, what method would you suggest? Thank you again in advance.

PGStats
Opal | Level 21

There have been countless papers written about this. Search "bootstrap confidence intervals" in your favorite search engine. The short story is that for most estimators the raw bootstrap confidence interval is pretty good. It is in fact used in many SAS procedures, without correction.

PG
mnayan
Calcite | Level 5

Thank you again for your comprehensive help!

FreelanceReinh
Jade | Level 19

Hi @mnayan and welcome to the SAS Support Communities!

 

I second PG's approach. See also the 2018 post Re: Simulation and outputs and the two blog articles linked therein for additional tips and background information as to why BY-group processing in the analysis procedure is more efficient than the macro loop you envisioned.

mnayan
Calcite | Level 5
Thanks, much appreciated!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 779 views
  • 0 likes
  • 3 in conversation