<?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 to create random samples from dataset? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100918#M5260</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think your set fun statement should be before the do loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Feb 2013 11:02:38 GMT</pubDate>
    <dc:creator>VD</dc:creator>
    <dc:date>2013-02-07T11:02:38Z</dc:date>
    <item>
      <title>How to create random samples from dataset?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100917#M5259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to perform oversampling on my dataset (~200,000 observations), which consist of a flag variable of value 1 or 0. I want 100 samples with each sample to contain all the observations with flag=1 (~100 of them in total) and then randomly select ~750 of observations that have flag = 0. However, I seem to have some difficulty in getting what I want. &lt;STRONG&gt;I ended up with ~10,000 observations in total for each sample&lt;/STRONG&gt;. &lt;STRONG&gt;And sometimes, my code takes forever to run&lt;/STRONG&gt;. Can someone advice me on what is wrong?&lt;/P&gt;&lt;P&gt;My code is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data oversamples;&lt;/P&gt;&lt;P&gt;do sample=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set fun;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to _N_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if flag= 1 or (flag=0 and ranuni(sample+7320) &amp;lt; 0.003) then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any advice.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 07:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100917#M5259</guid>
      <dc:creator>lavernal</dc:creator>
      <dc:date>2013-02-07T07:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to create random samples from dataset?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100918#M5260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think your set fun statement should be before the do loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 11:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100918#M5260</guid>
      <dc:creator>VD</dc:creator>
      <dc:date>2013-02-07T11:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create random samples from dataset?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100919#M5261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why dont you try PROC SURVEYSELECT, it picks random samples.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc surveyselect data=data_set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; method=srs n=100 out=data_random;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 11:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100919#M5261</guid>
      <dc:creator>akberali67</dc:creator>
      <dc:date>2013-02-07T11:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create random samples from dataset?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100920#M5262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi akberali,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My output is now really random, I want it to include all elements with flag=1 and then randomly select ~800 elements with flag=0. Is it possible to create that using the proc surveyselect?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the advice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 11:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100920#M5262</guid>
      <dc:creator>lavernal</dc:creator>
      <dc:date>2013-02-07T11:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create random samples from dataset?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100921#M5263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the STRATA option and set the sample rate for the "rare event category" to be 100%. See &lt;A href="http://www.nesug.org/proceedings/nesug07/sa/sa02.pdf" title="http://www.nesug.org/proceedings/nesug07/sa/sa02.pdf"&gt;http://www.nesug.org/proceedings/nesug07/sa/sa02.pdf&lt;/A&gt;, beginning at the bottom of page 2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 13:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-random-samples-from-dataset/m-p/100921#M5263</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-02-07T13:11:56Z</dc:date>
    </item>
  </channel>
</rss>

