<?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: pick a random value from a list for a variable, with or without replacement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393633#M94820</link>
    <description>&lt;P&gt;All the information you need is at&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2016/02/15/essential-sampling-methods.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2016/02/15/essential-sampling-methods.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you have to generate each variable separately. &amp;nbsp;It is not clear if you want all 50 observations or a subset. It is also not clear if you need the&amp;nbsp;values in random order or in the original order. &amp;nbsp;The easiest way is to use the SAMPLE function in SAS/IML, but since you posted to the Base SAS Community, here is a PROC-based solution to get you started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname temp "C:\Temp";
data Have;
set temp.have;
call streaminit(1);
u = rand("uniform");
run;

/* without replacement (SRS) */
proc sort data=Have out=SRS(rename=(value=random_value_norepeat));
by u;
run;

/* with replacement (URS) */
proc surveyselect noprint data=temp.Have
     method=urs  
     seed=2
     samprate=1
     outhits
     out=URS(rename=(value=vandom_value_repeat));
run;

/* if you want URS in random order, then generate random uniform and sort */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Sep 2017 17:12:58 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-09-06T17:12:58Z</dc:date>
    <item>
      <title>pick a random value from a list for a variable, with or without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393611#M94817</link>
      <description>&lt;P&gt;For the attached sample dataset, I would like to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) generate a variable "random_value_norepeat" which equals to a randomly selected number from the variable "value" (any number from the "value" can only be selected for one time, or put it another way, sample without replacement), and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) generate another variable&amp;nbsp;&lt;SPAN&gt;"random_value_repeat" which also equals to a randomly selected number from the variable "value", but the number from the "value" can be selected more than once&amp;nbsp;(sample with replacement).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Many thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 16:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393611#M94817</guid>
      <dc:creator>JacAder</dc:creator>
      <dc:date>2017-09-06T16:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: pick a random value from a list for a variable, with or without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393630#M94818</link>
      <description>&lt;P&gt;With replacement&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2014/01/29/sample-with-replacement-in-sas.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2014/01/29/sample-with-replacement-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without replacement&lt;/P&gt;
&lt;P&gt;Google turns up lots of examples&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 17:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393630#M94818</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-06T17:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: pick a random value from a list for a variable, with or without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393632#M94819</link>
      <description>&lt;P&gt;proc surveyselect does both. method=srs selects without replacement, method=urs does so with replacement.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 17:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393632#M94819</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-06T17:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: pick a random value from a list for a variable, with or without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393633#M94820</link>
      <description>&lt;P&gt;All the information you need is at&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2016/02/15/essential-sampling-methods.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2016/02/15/essential-sampling-methods.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you have to generate each variable separately. &amp;nbsp;It is not clear if you want all 50 observations or a subset. It is also not clear if you need the&amp;nbsp;values in random order or in the original order. &amp;nbsp;The easiest way is to use the SAMPLE function in SAS/IML, but since you posted to the Base SAS Community, here is a PROC-based solution to get you started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname temp "C:\Temp";
data Have;
set temp.have;
call streaminit(1);
u = rand("uniform");
run;

/* without replacement (SRS) */
proc sort data=Have out=SRS(rename=(value=random_value_norepeat));
by u;
run;

/* with replacement (URS) */
proc surveyselect noprint data=temp.Have
     method=urs  
     seed=2
     samprate=1
     outhits
     out=URS(rename=(value=vandom_value_repeat));
run;

/* if you want URS in random order, then generate random uniform and sort */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2017 17:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/pick-a-random-value-from-a-list-for-a-variable-with-or-without/m-p/393633#M94820</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-09-06T17:12:58Z</dc:date>
    </item>
  </channel>
</rss>

