I am a beginner SAS user. In this simulation, there is an initial value of the variable called "p", but there will be a new value (called "newp" in code below") calculated by SAS for each iteration in the simulation. How can I get this value that is created in each iteration to be used in the iteration that follows? See code below.
That is, when gen=1, the value of "p" is 0.00005. Based on the results of the simulation a "newp" will be calculated using the entered formula. This "newp" should be used for gen=2, where again, another different "newp" is calculated and should be used in gen=3, and so forth.
data a;
do gen=1 to 10;
seed=47639087;
expon=2*ranuni(seed) + 4;
n=round(10**expon,1);
p=.00005;
q=1-p;
NumRR = round(n*p*p,1);
NumSR = round(2*n*p*q,1);
NumSS = round(n*q*q,1);
newp=(NumRR + .5*NumSR) / (Numrr + numsr + numss);
diffp=p-newp;
newq=(NumSS + .5*NumSR)/ (Numrr + numsr + numss);
diffq=q-newq;
output;
end;
data a;
newp=.00005;
do gen=1 to 10;
seed=47639087;
expon=2*ranuni(seed) + 4;
n=round(10**expon,1);
p=.newp;
q=1-p;
NumRR = round(n*p*p,1);
NumSR = round(2*n*p*q,1);
NumSS = round(n*q*q,1);
newp=(NumRR + .5*NumSR) / (Numrr + numsr + numss);
diffp=p-newp;
newq=(NumSS + .5*NumSR)/ (Numrr + numsr + numss);
diffq=q-newq;
output;
end;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.