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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 530 views
  • 0 likes
  • 3 in conversation