<?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 random number between 8 and 50, and must adding up to 50 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600381#M173530</link>
    <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is someone can help me out? I need to generate 3 random numbers between 8 to 50, and the sum of these three number must be 50. I really appreciated your help.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2019 13:41:00 GMT</pubDate>
    <dc:creator>89lilywang89</dc:creator>
    <dc:date>2019-10-30T13:41:00Z</dc:date>
    <item>
      <title>random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600381#M173530</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is someone can help me out? I need to generate 3 random numbers between 8 to 50, and the sum of these three number must be 50. I really appreciated your help.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600381#M173530</guid>
      <dc:creator>89lilywang89</dc:creator>
      <dc:date>2019-10-30T13:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600382#M173531</link>
      <description>&lt;P&gt;I have no idea.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But since the smallest two numbers possible are 8 and 9 then largest possible number must be 33 and not 50.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600382#M173531</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-30T13:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600383#M173532</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297499"&gt;@89lilywang89&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is someone can help me out? I need to generate 3 random numbers between 8 to 50, and the sum of these three number must be 50. I really appreciated your help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the first random number is 10 and the second random number is 25, then the third number CANNOT be considered random ... and I'm sure you can figure out how to get 10 + 25 + (third number) to equal 50. Is that what you want? Or have I totally misunderstood the question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the question fails to make any logical sense on another level. Suppose the first random number is 49. Then what? How do you pick two additional random numbers between 8 and 50, such that the total is 50?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600383#M173532</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-30T13:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600388#M173534</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297499"&gt;@89lilywang89&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The randomness of this question seems quite restricted.. What happens if the first number we draw is 49?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600388#M173534</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-30T13:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600389#M173535</link>
      <description>&lt;P&gt;This isn't right but it'll get you close. Maybe spark some ideas of your own.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let NObs = 10;
data Test(keep=u n1 n2 n3);
call streaminit(123);
a = -1; b = 1;
Min = 8; Max = 34;
do i = 1 to &amp;amp;NObs;
   u = rand("Uniform");            /* decimal values in (0,1)    */
   n1 = min + floor((1+Max-Min)*u); /* integer values in Min..Max */
   n2 = min + floor((1+Max-Min)*u); /* integer values in Min..Max */
   n3 = 50 - n1 - n2;
   output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600389#M173535</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-30T13:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600391#M173536</link>
      <description>&lt;P&gt;Thank you for the reply. The situation is that I need to&amp;nbsp;randomly select 50 observations for my dataset. And there are three groups in the&amp;nbsp; dataset, I need at least 8 observation from each group. I am thinking to use&amp;nbsp;&lt;STRONG&gt;proc surveyselect&amp;nbsp;&lt;/STRONG&gt;to select my sample. So I need "three&amp;nbsp;random number between 8 and 50, and must adding up to 50" using as &lt;STRONG&gt;sampsize&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600391#M173536</guid>
      <dc:creator>89lilywang89</dc:creator>
      <dc:date>2019-10-30T13:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600392#M173537</link>
      <description>&lt;P&gt;I think you should think a bit about what distribution you want on those 3 numbers. But one way to do it could be like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nwant=10; /* how many obs do you want */
%let min=8;
%let max=50;
data test;
  do _N_=1 to &amp;amp;nwant;
    do until(sum(x,y,z)=50);
      x=ceil(rand('UNIFORM',&amp;amp;min,&amp;amp;min+2*(&amp;amp;max-&amp;amp;min)/3));
      y=ceil(rand('UNIFORM',&amp;amp;min,&amp;amp;min+2*(&amp;amp;max-&amp;amp;min)/3));
      z=ceil(rand('UNIFORM',&amp;amp;min,&amp;amp;min+2*(&amp;amp;max-&amp;amp;min)/3));
      end;
   output;
   end;
 stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600392#M173537</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-30T13:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600393#M173538</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297499"&gt;@89lilywang89&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is someone can help me out? I need to generate 3 random numbers between 8 to 50, and the sum of these three number must be 50. I really appreciated your help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are numbers between 8 and 50 limited to integers? If not I don't really see any practical solution (or use).&lt;/P&gt;
&lt;P&gt;One way that may give you something to use: generate all the integers between 8 and 50 for 3 variables, add them and keep the totals of 50. Then select a random record. This is one way to accomplish that idea:&lt;/P&gt;
&lt;PRE&gt;data work.start;
   do num1 = 8 to 50;
   do num2 = 8 to 50;
   do num3 = 8 to 50;
      randvalue = rand('uniform');
      if sum(num1,num2,num3)= 50 then output;
   end;
   end;
   end;
run;

proc sort data=work.start;
   by randvalue;
run;

proc print data=work.start (obs=1);
run;&lt;/PRE&gt;
&lt;P&gt;The sort by a random value and using the first sorted order value randomizes the variable combinations.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600393#M173538</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-30T13:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600395#M173539</link>
      <description>Other than changing your Max to 34 (as anything above 34 is irrelevant... 8+8 = 16, 50-16 = 34) this looks like a correct way of doing it.</description>
      <pubDate>Wed, 30 Oct 2019 14:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600395#M173539</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-30T14:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600396#M173540</link>
      <description>&lt;P&gt;Thanks so much. It works perfectly.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 14:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600396#M173540</guid>
      <dc:creator>89lilywang89</dc:creator>
      <dc:date>2019-10-30T14:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600399#M173543</link>
      <description>&lt;P&gt;Thanks so much. It works perfectly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 14:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600399#M173543</guid>
      <dc:creator>89lilywang89</dc:creator>
      <dc:date>2019-10-30T14:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600400#M173544</link>
      <description>&lt;P&gt;Some good points have already been raised by others which will need addressing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it might be of help if you explain the context / background to this question, e.g., what are the circumstances under which you need this solution or is it needed as part of a solution to another problem? In which case what is the original problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please provide more information, such as:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Can the random numbers be duplicates?&lt;/LI&gt;&lt;LI&gt;Do the numbers have to be integers? E.g., can 0.1 be used and is there any limit to the number of decimal places?&lt;/LI&gt;&lt;LI&gt;Is this part of some homework and do you have to use a particular method or function, etc. for practice purposes?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 14:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600400#M173544</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-10-30T14:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600657#M173672</link>
      <description>&lt;P&gt;One small note: You may want to tweak the code a bit, if by "between" you meant numbers including 8, which will not be in the solution I posted, because of the CEIL function. If you want the occasional 8 in your output, the easy way may be to change then MIN macro variable to 7.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 10:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600657#M173672</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-31T10:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: random number between 8 and 50, and must adding up to 50</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600754#M173708</link>
      <description>The 3rd number it's not random because it depends on the other 2, to sum 50.&lt;BR /&gt;generate two random numbers and the 3rd will be =50-(a+b)</description>
      <pubDate>Thu, 31 Oct 2019 17:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-number-between-8-and-50-and-must-adding-up-to-50/m-p/600754#M173708</guid>
      <dc:creator>u41054003</dc:creator>
      <dc:date>2019-10-31T17:41:59Z</dc:date>
    </item>
  </channel>
</rss>

