<?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: It's possible to generate random numbers with these conditions? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16551#M3052</link>
    <description>When you say that each set has the same mean, do you mean the exact same mean? &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
or should all be normal distributed with mean=5, sd=2 for example. &lt;BR /&gt;
&lt;BR /&gt;
You can look into the rand() function and then either truncate, discard or floor values that go outside of your range, but that may change your distribution. It really depends on what your SD and mean are though...ie a mean of 5 and sd of 1 would rarely have any values outside of 1 or 9. &lt;BR /&gt;
&lt;BR /&gt;
From all the criteria the sample size being different is actually the easiest to control! Same mean and between 1 and 9 will be the most difficult, in my opinion.</description>
    <pubDate>Thu, 24 Feb 2011 17:41:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2011-02-24T17:41:08Z</dc:date>
    <item>
      <title>It's possible to generate random numbers with these conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16550#M3051</link>
      <description>Hello, again.&lt;BR /&gt;
&lt;BR /&gt;
Can I generate random numbers with specific conditions, like this . . .&lt;BR /&gt;
&lt;BR /&gt;
"8 set of random numbers (a, b, c, d, e, f, g, and h)"&lt;BR /&gt;
- each set has the same 'mean' (arithmetic Mean)&lt;BR /&gt;
- the range of random numbers is 1-9&lt;BR /&gt;
- every set is normal distribution&lt;BR /&gt;
- but sample size for each set is difference for example :&lt;BR /&gt;
&lt;BR /&gt;
set a, sample size 30 (30 of random numbers)&lt;BR /&gt;
set b, sample size 50&lt;BR /&gt;
set c, sample size 80&lt;BR /&gt;
set d, sample size 100&lt;BR /&gt;
set e, sample size 200&lt;BR /&gt;
set f, sample size 300&lt;BR /&gt;
set g, sample size 500&lt;BR /&gt;
set h sample size 1,000&lt;BR /&gt;
&lt;BR /&gt;
thank you for your kindness and sorry about my broken english ^_^</description>
      <pubDate>Thu, 24 Feb 2011 10:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16550#M3051</guid>
      <dc:creator>s_chanon</dc:creator>
      <dc:date>2011-02-24T10:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: It's possible to generate random numbers with these conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16551#M3052</link>
      <description>When you say that each set has the same mean, do you mean the exact same mean? &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
or should all be normal distributed with mean=5, sd=2 for example. &lt;BR /&gt;
&lt;BR /&gt;
You can look into the rand() function and then either truncate, discard or floor values that go outside of your range, but that may change your distribution. It really depends on what your SD and mean are though...ie a mean of 5 and sd of 1 would rarely have any values outside of 1 or 9. &lt;BR /&gt;
&lt;BR /&gt;
From all the criteria the sample size being different is actually the easiest to control! Same mean and between 1 and 9 will be the most difficult, in my opinion.</description>
      <pubDate>Thu, 24 Feb 2011 17:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16551#M3052</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-02-24T17:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: It's possible to generate random numbers with these conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16552#M3053</link>
      <description>You could try the following code:  &lt;BR /&gt;
&lt;BR /&gt;
      data RandomValues;&lt;BR /&gt;
           samplesize = 300;  /* update to desired sample size*/&lt;BR /&gt;
           seed = date();   /*setting a seed for the random number generator*/&lt;BR /&gt;
           do i = 1 to samplesize;&lt;BR /&gt;
               obs = ceil((ranuni(seed) * 9)); /*change upper bound here */&lt;BR /&gt;
               output;&lt;BR /&gt;
         end;&lt;BR /&gt;
      run;</description>
      <pubDate>Fri, 25 Feb 2011 20:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16552#M3053</guid>
      <dc:creator>Rambo</dc:creator>
      <dc:date>2011-02-25T20:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: It's possible to generate random numbers with these conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16553#M3054</link>
      <description>Hi.&lt;BR /&gt;
I think your biggest problem is to define mu and sigma of Normal Distribution.&lt;BR /&gt;
Your mean " the range of random numbers is 1-9 " ,That is to mean mu=5, sigma is not quit sure,&lt;BR /&gt;
because basing my statistical knowledge , the valuefrom normal will 99.7% probability fall in between mu-3*sigma and mu+3*sigma (e.g ~N(0,1) ,the value will 99.7% probability fall in -3 and 3).&lt;BR /&gt;
So if as the rule of 3*sigma then sigma will be about 1.4, to make sure value fall in 1-9,&lt;BR /&gt;
I set sigma = 1.2, or you can change it more little.&lt;BR /&gt;
Remember sigma is relation with mu for your situation ( from 1-9).&lt;BR /&gt;
&lt;BR /&gt;
Another problem is arithmetic mean,Are you to mean (1+2+3+4)/4 ?&lt;BR /&gt;
In numeric calculated ,there can not be exactly matched,So I use round() function to &lt;BR /&gt;
match .1th.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let mu=5; *Normal Distribution 's position parameter;&lt;BR /&gt;
%let sigma=1.2; *Normal Distribution 's scale parameter;&lt;BR /&gt;
%let mean=5.0;  * Your arithmetic Mean;&lt;BR /&gt;
%let sample_size=500;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro normal(mu= , sigma= , sample_size= , mean=);&lt;BR /&gt;
 data normal_&amp;amp;sample_size ;&lt;BR /&gt;
 value=rand('normal',μ,σ); count+1; sum+value;&lt;BR /&gt;
 output;&lt;BR /&gt;
 do until(count = &amp;amp;sample_size);&lt;BR /&gt;
   value=rand('normal',μ,σ);count+1; sum+value;&lt;BR /&gt;
   if round(sum/count,.1) = &amp;amp;mean then output;&lt;BR /&gt;
     else do;&lt;BR /&gt;
            count+(-1);&lt;BR /&gt;
            sum+(-1)*value;&lt;BR /&gt;
          end;&lt;BR /&gt;
  end;&lt;BR /&gt;
 &lt;BR /&gt;
 run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%normal(mu=μ,sigma=σ,sample_size=&amp;amp;sample_size,mean=&amp;amp;mean)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 28 Feb 2011 06:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/It-s-possible-to-generate-random-numbers-with-these-conditions/m-p/16553#M3054</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-28T06:06:24Z</dc:date>
    </item>
  </channel>
</rss>

