<?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: How do I generate a random number between 0 and 1 with a normal distribution? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527735#M143940</link>
    <description>&lt;P&gt;The "problem" with the normal distribution is that it does not have defined lower/upper bounds. Theoretically, any value is possible, only with diminishing probability the farther away from the mean it is.&lt;/P&gt;
&lt;P&gt;The more data points you have, the higher the probability of exceeding any wanted minimum/maximum.&lt;/P&gt;
&lt;P&gt;So, when running this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do i = 1 to 1000;
  x1 = rand('normal',.5,.1);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I stayed well between 0 and 1, but with 10 million iterations I exceeded the bounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you don't want uniform distribution?&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 15:21:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-01-16T15:21:36Z</dc:date>
    <item>
      <title>How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527719#M143930</link>
      <description>&lt;P&gt;I am trying to randomize the numbers in&amp;nbsp;my dataset for a few different variables. The macro that I am using to do this is currently:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RandBetween(min, max);
   (&amp;amp;min + ((1+&amp;amp;max-&amp;amp;min)*abs(rand("normal"))))
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think my understanding of a normal distribution isn't correct since %RandBetween(0,1) seems to be returning numbers greater than 1 as well. This obviously will return an incorrect 'percentage' variable since I want that to have a maximum value of 1 (100%). Consequently, other variables that are generated like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;avg_opioid = %RandBetween(0,&amp;amp;max_avg_opioid.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;also seem to have values greater than their max (presumably because the rand("normal") function is returning numbers greater than 1. I have also tried rand("normal",0.5,0.5) but that doesn't seem to help either. At this point, I think my understanding of the normal distribution may be skewed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I go about limiting the return of rand("normal") to a min and max of 0 and 1 respectively?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 14:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527719#M143930</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2019-01-16T14:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527722#M143932</link>
      <description>&lt;P&gt;After the macro is resolved, you get&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(0 + ((1+1-0)*abs(rand("normal"))))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so you'll get numbers between 0 and 2.&lt;/P&gt;
&lt;P&gt;Change your macro to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RandBetween(min, max);
   (&amp;amp;min + ((&amp;amp;max-&amp;amp;min)*abs(rand("normal"))))
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 14:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527722#M143932</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-16T14:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527724#M143933</link>
      <description>I tried this and it still returns numbers greater than 1. Looking at the documentation of the rand function here (&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a001466748.htm#a002505417" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a001466748.htm#a002505417&lt;/A&gt;), it looks like the rand('NORMAL') function can return values greater than 1.</description>
      <pubDate>Wed, 16 Jan 2019 14:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527724#M143933</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2019-01-16T14:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527727#M143935</link>
      <description>&lt;P&gt;Are you sure you want to create a 'percentage variable' using the normail distribution? A N(0,1) distribution is not restricted to values between 0 and 1. It is a normal distribution with mean 0 and variance 1 ..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not actually need the normail, then simply do this to get a value between 0 and 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x=rand('uniform');
put x;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 15:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527727#M143935</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-16T15:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527732#M143938</link>
      <description>&lt;P&gt;Unfortunately, for the purposes of what I am trying to do with the data, I need it to be a normal distribution.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 15:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527732#M143938</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2019-01-16T15:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527735#M143940</link>
      <description>&lt;P&gt;The "problem" with the normal distribution is that it does not have defined lower/upper bounds. Theoretically, any value is possible, only with diminishing probability the farther away from the mean it is.&lt;/P&gt;
&lt;P&gt;The more data points you have, the higher the probability of exceeding any wanted minimum/maximum.&lt;/P&gt;
&lt;P&gt;So, when running this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do i = 1 to 1000;
  x1 = rand('normal',.5,.1);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I stayed well between 0 and 1, but with 10 million iterations I exceeded the bounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you don't want uniform distribution?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 15:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527735#M143940</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-16T15:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate a random number between 0 and 1 with a normal distribution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527740#M143944</link>
      <description>&lt;P&gt;Awesome, this was exactly what I needed. It understand that the asymptotic nature of the bell curve doesn't allow for bounds but that is okay since 1 or 2 observations over 100% out of 100,000 is reasonable. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 15:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-generate-a-random-number-between-0-and-1-with-a-normal/m-p/527740#M143944</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2019-01-16T15:28:12Z</dc:date>
    </item>
  </channel>
</rss>

