<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Randomly generate an outcome that has a certain probability in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298922#M15903</link>
    <description>&lt;P&gt;Sorry, I should have&amp;nbsp;mentioned that the CALL STREAMINIT call sets a "seed" for the random value stream. &amp;nbsp;If you want it to produce different values every time you run, you can use zero as a seed:&lt;/P&gt;
&lt;P&gt;call streaminit(0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read more about random number streams in the article &lt;A href="http://blogs.sas.com/content/iml/2011/08/31/random-number-streams-in-sas-how-do-they-work.html" target="_self"&gt;"Random number streams in SAS: How do they work?"&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2016 12:45:31 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-09-16T12:45:31Z</dc:date>
    <item>
      <title>Randomly generate an outcome that has a certain probability</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298914#M15899</link>
      <description>&lt;P&gt;Hi I would like to create a field in my dataset called with two outcomes: "Win" or "Lose"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each row in my dataset I have a Win_Prob and I would like this outcome field to populate based on the prob. So if the probability is 20% than if I ran the dataset 5 times it would populate "Win" one in 5 times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done easily?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 11:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298914#M15899</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2016-09-16T11:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly generate an outcome that has a certain probability</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298915#M15900</link>
      <description>&lt;P&gt;You want exact probabilities?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look into either rand('Bernoulli', probability)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or randtable()&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 11:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298915#M15900</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-16T11:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly generate an outcome that has a certain probability</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298917#M15901</link>
      <description>&lt;P&gt;Because it is random, you won't get 1 win and 4 losses if you run the program 5 times, just like if you flip a coin twice you don't always see 1 head and 1 tail. &amp;nbsp;However, ON AVERAGE, you will see the specified probabilities if you repeat the experiment many many many times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the result of each individual trial, you can use the rand("Bernoulli") function. The following reads the probabilities from a data set and then repeats a Bernoulli trial (basically a coin flip with the given probability) five times:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Prob;
input Win_Prob @@;
datalines;
0.2 0.5 0.9
;

data Wins;
call streaminit(1234);
set Prob;
do trial = 1 to 5;
   Win = rand("Bernoulli", Win_Prob);
   output;
end;
run;

proc freq data=Wins;
tables Win_Prob * Win / nocum nocol nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If all you care about is the summary statistics (how many wins/losses were observed), you can use the Binomial distribution, which gives you the numbers of wins in N trials. In the following, I set N=50 so that you can see that about 20%, 50% and 90% of the trials are "successes":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data AllWins;
call streaminit(1234);
set Prob;
nTrials = 50;
NumWins = rand("Binomial", Win_Prob, nTrials);
run;

proc print data=AllWins;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 12:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298917#M15901</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-09-16T12:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly generate an outcome that has a certain probability</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298921#M15902</link>
      <description>&lt;P&gt;Thanks Rick&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the first piece of code and it works but when i run it again it the values "Win" field don't change. I thought it would generate different values each time you run the data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 12:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298921#M15902</guid>
      <dc:creator>brophymj</dc:creator>
      <dc:date>2016-09-16T12:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly generate an outcome that has a certain probability</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298922#M15903</link>
      <description>&lt;P&gt;Sorry, I should have&amp;nbsp;mentioned that the CALL STREAMINIT call sets a "seed" for the random value stream. &amp;nbsp;If you want it to produce different values every time you run, you can use zero as a seed:&lt;/P&gt;
&lt;P&gt;call streaminit(0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read more about random number streams in the article &lt;A href="http://blogs.sas.com/content/iml/2011/08/31/random-number-streams-in-sas-how-do-they-work.html" target="_self"&gt;"Random number streams in SAS: How do they work?"&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 12:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Randomly-generate-an-outcome-that-has-a-certain-probability/m-p/298922#M15903</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-09-16T12:45:31Z</dc:date>
    </item>
  </channel>
</rss>

