<?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: Monte Carlo / Random number in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155289#M40774</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A stub of an example;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data one two three;&lt;/P&gt;&lt;P&gt;/* get values from somewhere*/&lt;/P&gt;&lt;P&gt;if category=1 then output one;&lt;/P&gt;&lt;P&gt;else if category=2 then output two;&lt;/P&gt;&lt;P&gt;else if category=3 then output three;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Feb 2015 18:16:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-02-05T18:16:27Z</dc:date>
    <item>
      <title>Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155285#M40770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the problem, I have a list of numbers and I want to randomly put them into three buckets.&amp;nbsp; This will be a no replacement.&amp;nbsp; I want 50% of the numbers to go in bucket A, 30% to go into bucket B, and 20% to go in bucket C.&amp;nbsp; From this I want to know the mean of each bucket, then run it 100 times and have a sheet that says the mean of each bucket for each run.&amp;nbsp; I have no idea where to start.&amp;nbsp; Please help.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 15:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155285#M40770</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2015-02-05T15:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155286#M40771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Homework?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do this in Base SAS (DATA step + PROC MEANS) or in SAS/IML. By coincidence, those are the same percentages I use in my book &lt;EM&gt;&lt;A href="http://support.sas.com/publishing/authors/wicklin.html"&gt;Simulating Data with SAS&lt;/A&gt;&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt; To do the experiment one time, look at the article &lt;A class="active_link" href="http://blogs.sas.com/content/iml/2011/07/13/simulate-categorical-data-in-sas/"&gt;"Simulate categorical data in SAS".&lt;/A&gt;&lt;/P&gt;&lt;P&gt;To write this as a Monte Carlo simulation, look at the article &lt;A href="http://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way/"&gt;"Simulation in SAS: The slow way or the BY way"&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone who has a copy of my book can look on p. 130-131 for an interesting twist to this problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 15:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155286#M40771</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-02-05T15:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155287#M40772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not homework, for actual work.&amp;nbsp; I guess I'm not following on how to create multiple sets.&amp;nbsp; I see how to create one set.&amp;nbsp; Can you elaborate?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 16:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155287#M40772</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2015-02-05T16:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155288#M40773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dr. Wicklin's text, "Simulating Data Using SAS", is phenomenal! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I highly recommend it.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Brian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 18:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155288#M40773</guid>
      <dc:creator>bhfield</dc:creator>
      <dc:date>2015-02-05T18:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155289#M40774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A stub of an example;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data one two three;&lt;/P&gt;&lt;P&gt;/* get values from somewhere*/&lt;/P&gt;&lt;P&gt;if category=1 then output one;&lt;/P&gt;&lt;P&gt;else if category=2 then output two;&lt;/P&gt;&lt;P&gt;else if category=3 then output three;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 18:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155289#M40774</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-02-05T18:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155290#M40775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use &lt;STRONG&gt;proc surveyselect&lt;/STRONG&gt; with the &lt;STRONG&gt;GROUPS=()&lt;/STRONG&gt; option :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Test data */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call streaminit(876857);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do id = 1 to 64;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = rand("NORMAL");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Calculate the bucket sizes */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; round(0.5*count(*)) as n50, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; round(0.3*count(*)) as n30,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(*) - calculated n50 - calculated n30 as n20&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;into :n50, :n30, :n20&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Generate random groups, 100 times */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc surveyselect data=test out=sample rep=100 groups=(&amp;amp;n50 &amp;amp;n30 &amp;amp;n20); run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Calculate group means */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table stats as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select replicate, groupID as bucket, mean(x) as meanX&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from sample&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by replicate, groupID;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 18:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155290#M40775</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-02-05T18:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155291#M40776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PGStats&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The groups option is causing a syntax error.&amp;nbsp; It seems groups is not an option for this proc &lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_surveyselect_sect007.htm" title="http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_surveyselect_sect007.htm"&gt;SAS/STAT(R) 9.2 User's Guide, Second Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It is possible it is another option?&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 19:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155291#M40776</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2015-02-05T19:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155292#M40777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry for the confusion. Somehow I misread the phrase "I have a list of numbers."&amp;nbsp; You are doing resampling rather than pure simulation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is always an issue with questions like this: Do you want EXACTLY 50%, 30%, 20%, or do you want to sample with probability 0.5, 0.3, and 0.2.&amp;nbsp; I assume the latter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As PG says, the general tool for resampling is PROC SURVEYSELECT. For this simple case you could also do the sampling yourself by assigning the "buckets" in a DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;keep x;&lt;BR /&gt;call streaminit(876857);&lt;BR /&gt;do i = 1 to 64;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; x = rand("NORMAL");&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* randomly assign numbers to bins; repeat 100 times */&lt;BR /&gt;%let NumSamples = 100;&lt;BR /&gt;data Many; &lt;BR /&gt;set test;&lt;BR /&gt;do SampleID = 1 to &amp;amp;NumSamples;&amp;nbsp; /* 1. duplicate sample */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; bin = rand("Table", 0.5, 0.3, 0.2); /* assign to bin */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* prepare for BY-group analysis */ &lt;BR /&gt;proc sort data=Many;&lt;BR /&gt;by SampleID;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* create "sheet that says the mean of each bucket for each run" */&lt;BR /&gt;proc means data=Many noprint; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; by SampleID;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* 2. compute many statistics */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; class bin;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; var x;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output out=OutStats(where=(_TYPE_=1)) mean=SampleMean;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=OutStats;&lt;BR /&gt;var SampleID bin _FREQ_ SampleMean; &lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 19:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155292#M40777</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-02-05T19:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155293#M40778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, I did not mean probability.&amp;nbsp; I meant if my list was 10 then A would have 5 of the numbers, B would have 3 of the numbers, and C would have the last two numbers in it. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 19:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155293#M40778</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2015-02-05T19:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155294#M40779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm very sorry for the confusion.&lt;/P&gt;&lt;P&gt;If this was my list&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="64"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="64"&gt;DRG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;&lt;P&gt;54&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example one run would have&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="192"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="64"&gt;A&lt;/TD&gt;&lt;TD width="64"&gt;B&lt;/TD&gt;&lt;TD width="64"&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;2&lt;/TD&gt;&lt;TD align="right"&gt;2&lt;/TD&gt;&lt;TD align="right"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;3&lt;/TD&gt;&lt;TD align="right"&gt;5&lt;/TD&gt;&lt;TD align="right"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;13&lt;/TD&gt;&lt;TD align="right"&gt;19&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;22&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="20"&gt;54&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I want to know the mean of each and say&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="303"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="111"&gt;Run Average&lt;/TD&gt;&lt;TD width="64"&gt;A&lt;/TD&gt;&lt;TD width="64"&gt;B&lt;/TD&gt;&lt;TD width="64"&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Run 1 Average&lt;/TD&gt;&lt;TD align="right"&gt;18.8&lt;/TD&gt;&lt;TD align="right"&gt;8.666667&lt;/TD&gt;&lt;TD align="right"&gt;4.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 19:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155294#M40779</guid>
      <dc:creator>weweaw</dc:creator>
      <dc:date>2015-02-05T19:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155295#M40780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Ricks code is correct, what if you had 20 observations, you'd want 10 in the first group, 6 in the second and 4 in the third. That's what the probability does in his code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 20:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155295#M40780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-02-05T20:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155296#M40781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using SAS 9.4. This would certainly work in 9.2 :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call streaminit(876857);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do id = 1 to 64;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = rand("NORMAL");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; round(0.5*count(*)) as n50, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; round(0.3*count(*)) as n30&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;into :n50, :n30&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sample;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do replicate = 1 to 100;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rnd = rand("UNIFORM");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=sample; by replicate rnd; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sampleGroups;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set sample; by replicate;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.replicate then n = 0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;n + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if n &amp;lt;= &amp;amp;n50 then bucket = "A";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else if n &amp;lt;= &amp;amp;n50 + &amp;amp;n30 then bucket = "B";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else bucket = "C";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;drop n rnd;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table stats as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select replicate, bucket, mean(x) as meanX&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from sampleGroups&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by replicate, bucket;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 20:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155296#M40781</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-02-05T20:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Monte Carlo / Random number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155297#M40782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am considering using proc rank .&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data class;
 set sashelp.class;
 ran=ranuni(0);
 keep ran;
run;
proc rank data=class out=temp groups=10;
 var ran;
 ranks rank;
run;
data want;
 merge temp(where=(rank in (0:4)) rename=(ran=A))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp(where=(rank in (5:7)) rename=(ran=B))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp(where=(rank in (8 9)) rename=(ran=C)) ;
 drop rank;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 09:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Monte-Carlo-Random-number/m-p/155297#M40782</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-02-06T09:06:58Z</dc:date>
    </item>
  </channel>
</rss>

