BookmarkSubscribeRSS Feed
cu139
Calcite | Level 5

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;

1 REPLY 1
DBailey
Lapis Lazuli | Level 10

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 788 views
  • 0 likes
  • 2 in conversation