Thank you so much Rick_SAS This is really helpful So now I think I just need help eliminating the IF and Then statements. My code is a bit more complicated and I am wondering if you could help me eliminate them in the sample code below. I was not able to find the best wat to do it. especially because I am trying to simulate MI (myocardial infarction) among those who do not have it in the previous step. Thank you Proc fcmp outlib=work.funcs.link; /*to create an Expit function*/
function expit(LinearCombination);
n = (1/(1 + exp(-(LinearCombination))));
return (n);
endsub;
quit;
/*End of function generation*/
options cmplib=work.funcs ;
Data param;
array arMEANAGE {&start:&endpoint}(32, 40, 58);
array arMEANBP {&start:&endpoint}(132, ., .);
array arMEANMI {&start:&endpoint}(0, ., .);
array arInterBP {&start:&endpoint}(., 80, 90);
array arInterMI {&start:&endpoint}(., -2.75, -2.09);
array arBeta_BP_AGE {&start:&endpoint}(., 0.001, 0.002);
array arBeta_MI_AGE {&start:&endpoint}(., 0.002, 0.001);
array arBeta_MI_BP {&start:&endpoint}(., 0.003, 0.009);
run;
Data simwide;
set param;
call streaminit(053018);
do replicate= 1 to &reps; /*Number of replications*/
do Envid = 1 to &numNeigh; /*Number of neighborhoods*/
NeighborhoodScore = rand('normal', 2, 1);
array arAGE {&start:&endpoint};
array arBP {&start:&endpoint};
array arMI {&start:&endpoint};
array arMEANAGE {&start:&endpoint};
array arMEANBP {&start:&endpoint};
array arMEANMI {&start:&endpoint};
array arInterBP {&start:&endpoint};
array arInterMI {&start:&endpoint};
array arBeta_BP_AGE {&start:&endpoint};
array arBeta_MI_AGE {&start:&endpoint};
array arBeta_MI_BP {&start:&endpoint};
do id = 1 to &sampsize; /*size of each sample*/
do t=&start to &endpoint; /*time points*/
if t=&start then
do;
arAGE{t} = rand('normal',arMEANAGE{t}, 1);
arBP{t} = rand('normal',arMEANBP{t}, 1);
arMI{t} = arMEANMI{t};
end;
else if t=1 then
do;
arAGE{t} = rand('normal',arMEANAGE{t-1} + 1, 2);
arBP{t} = rand('normal',arInterBP{t} + arBeta_BP_AGE{t}*arAGE{t-1}, 1);
if (arMI{t-1}=0) then
do;
arMI{t} = rand('bernoulli',expit(arInterMI{t} + arBeta_MI_AGE{t}*arAGE{t-1} + arBeta_MI_BP{t}*arBP{t-1}));
end;
else
do;
arMI{t}=.;
end;
end;
else if t=&endpoint then
do;
arAGE{t} = rand('normal',arMEANAGE{t-1} + 1, 3);
arBP{t} = rand('normal',arInterBP{t} + arBeta_BP_AGE{t}*arAGE{t-1}, 1);
if (arMI{t-1}=0) then
do;
arMI{t} = rand('bernoulli',expit (arInterMI{t} + arBeta_MI_AGE{t}*arAGE{t-1} + arBeta_MI_BP{t}*arBP{t-1}));
end;
else
do;
arMI{t}=.;
end;
end;
end;
output;
end;
end;
end;
run;
... View more