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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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