<?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 The IML equivalent of the R &amp;quot;sample&amp;quot; function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22804#M100</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Does anyone know what is the SAS/IML equivalent of the R "sample" function?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Eyal</description>
    <pubDate>Tue, 26 Oct 2010 13:15:44 GMT</pubDate>
    <dc:creator>EyalGonen</dc:creator>
    <dc:date>2010-10-26T13:15:44Z</dc:date>
    <item>
      <title>The IML equivalent of the R "sample" function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22804#M100</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Does anyone know what is the SAS/IML equivalent of the R "sample" function?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Eyal</description>
      <pubDate>Tue, 26 Oct 2010 13:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22804#M100</guid>
      <dc:creator>EyalGonen</dc:creator>
      <dc:date>2010-10-26T13:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: The IML equivalent of the R "sample" function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22805#M101</link>
      <description>Are you sampling with replacement or without? Equal probability or unequal?&lt;BR /&gt;
&lt;BR /&gt;
For equal-prob sampling without replacement, use permutations. I just did a series of blog posts on generating permutations in IML:&lt;BR /&gt;
&lt;A href="http://blogs.sas.com/iml/index.php?/archives/16-Generating-Random-Permutations.html" target="_blank"&gt;http://blogs.sas.com/iml/index.php?/archives/16-Generating-Random-Permutations.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
For sampling with replacement, I present a a complete module (equal or unequal probabilities) in Chapter 12 of my book &lt;I&gt;Statistial Programming with SAS/IML Stoftware&lt;/I&gt;. Within the next few weeks, the programs for my book should be available for download at &lt;A href="http://support.sas.com/publishing/authors/wicklin.html" target="_blank"&gt;http://support.sas.com/publishing/authors/wicklin.html&lt;/A&gt; &lt;BR /&gt;
&lt;BR /&gt;
Since the code isn't posted there yet, here's some (less general) code for the case of random sampling with replacement under uniform probability:&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
/** Module for random sampling with replacement and uniform probability.&lt;BR /&gt;
   Assume A is row vector with k elements. **/&lt;BR /&gt;
start SampleReplaceUni(A, nSamples, nRep);&lt;BR /&gt;
k = ncol(A); /** number of elements **/&lt;BR /&gt;
results = j(nSamples, nRep); /** allocate result matrix **/&lt;BR /&gt;
call randgen(results, "Uniform"); /** fill with random U(0,1) **/&lt;BR /&gt;
results = ceil(k*results);  /** convert to integers 1,2,...k **/&lt;BR /&gt;
return (shape(A[results], nSamples)); /** reshape and return from A **/&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
call randseed(1234);&lt;BR /&gt;
/** Draw 5 samples from {1,2,...,8}. Do it 10 times. **/&lt;BR /&gt;
s = SampleReplaceUni(1:8, 10, 5);&lt;BR /&gt;
print s;</description>
      <pubDate>Tue, 26 Oct 2010 14:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22805#M101</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2010-10-26T14:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: The IML equivalent of the R "sample" function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22806#M102</link>
      <description>Hello Rick,&lt;BR /&gt;
&lt;BR /&gt;
I am sampling with replacement and with unequal probabilities.&lt;BR /&gt;
Specifically, this is the R statement:&lt;BR /&gt;
&lt;BR /&gt;
mu &amp;lt;- sample(c(4,12),size=1000,replace=T,prob=c(0.75,0.25))&lt;BR /&gt;
&lt;BR /&gt;
Is the code you wrote doing this?&lt;BR /&gt;
Is there no built-in IML (or IMLPlus) function for this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Eyal</description>
      <pubDate>Wed, 27 Oct 2010 09:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22806#M102</guid>
      <dc:creator>EyalGonen</dc:creator>
      <dc:date>2010-10-27T09:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: The IML equivalent of the R "sample" function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22807#M103</link>
      <description>The previous module is for equal probability.  For unequal prob, use the following:&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
/** Module for random sampling with replacement and unequal probability.&lt;BR /&gt;
 *  Assume A is row vector with k elements and &lt;BR /&gt;
 *  PROB is vector of probabilities {p1, p2, ..., pk}. **/&lt;BR /&gt;
start SampleReplaceUneq(A, nSamples, nRep, prob);&lt;BR /&gt;
   results = j(nSamples, nRep); /** allocate result matrix **/&lt;BR /&gt;
   call randgen(results, "Table", prob); /** fill with 1,2,...k **/&lt;BR /&gt;
   return (shape(A[results], nSamples)); /** reshape and return from A **/&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
call randseed(1234);&lt;BR /&gt;
set = {4 12};&lt;BR /&gt;
k = ncol(set);&lt;BR /&gt;
/** Resample from the set with given probabilities. Do it 1000 times. **/&lt;BR /&gt;
mu = SampleReplaceUneq(set, 1000, k, {0.75 0.25});</description>
      <pubDate>Wed, 27 Oct 2010 12:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22807#M103</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2010-10-27T12:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: The IML equivalent of the R "sample" function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22808#M104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update: SAS/IML 12.1 (SAS 9.3m2) supports the &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66112/HTML/default/viewer.htm#imlug_langref_sect368.htm"&gt;SAMPLE function&lt;/A&gt;, which supports drawing samples with or without replacement from finite sets, with equal or unequal probabilities.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 13:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/The-IML-equivalent-of-the-R-quot-sample-quot-function/m-p/22808#M104</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-08-15T13:31:05Z</dc:date>
    </item>
  </channel>
</rss>

