<?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: set variable equal to a randomly chosen value from a list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364838#M86574</link>
    <description>&lt;P&gt;If you only want to select random As, Bs, and Cs, the following code will take care of it:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
	do i=1 to 10;
	random_ABC = substr('ABC',ceil(ranuni(0)*3),1);
	output;
   	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Jun 2017 06:31:11 GMT</pubDate>
    <dc:creator>Yegen</dc:creator>
    <dc:date>2017-06-07T06:31:11Z</dc:date>
    <item>
      <title>set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364835#M86572</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting the following for each observation in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x=SelectRandomlyFrom("A","B","C")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's it. &amp;nbsp;I can use ranuni or proc surveyselect to select one of the options but i can't figure out how to set x equal to the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't matter to me if my choices have to be in a dataset or simply a typed list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 06:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364835#M86572</guid>
      <dc:creator>the_sheriff</dc:creator>
      <dc:date>2017-06-07T06:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364838#M86574</link>
      <description>&lt;P&gt;If you only want to select random As, Bs, and Cs, the following code will take care of it:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
	do i=1 to 10;
	random_ABC = substr('ABC',ceil(ranuni(0)*3),1);
	output;
   	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Jun 2017 06:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364838#M86574</guid>
      <dc:creator>Yegen</dc:creator>
      <dc:date>2017-06-07T06:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364840#M86576</link>
      <description>&lt;P&gt;RANTBL() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1kxey71grroain1k5e0j8n69vj3.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1kxey71grroain1k5e0j8n69vj3.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 06:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364840#M86576</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-07T06:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364900#M86602</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77192"&gt;@the_sheriff&lt;/a&gt;: The CHOOSEC is probably the easiest way in your example:&lt;/P&gt;&lt;PRE&gt;x=ChooseC(ceil(Rand('UNIFORM')*3),"A","B","C");&lt;/PRE&gt;&lt;P&gt;If your data is in an array, this is the format:&lt;/P&gt;&lt;PRE&gt;array values c1-c60;
x=ChooseC(ceil(Rand('UNIFORM')*dim(values)),of values(*));&lt;/PRE&gt;&lt;P&gt;I recommend using RAND() instead of RANUNI(), as it is a better pseudorandom algorithm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 10:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364900#M86602</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-06-07T10:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364956#M86627</link>
      <description>&lt;P&gt;You can generalize&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;'s solution to the case of unequal probabilities, as described in the blog post&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/07/13/simulate-categorical-data-in-sas.html" target="_self"&gt;"Simulate categorical data in SAS"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Sample; 
keep i j x; 
array prob [3] (0.5 0.2 0.3);       /* unequal probabilities */
array values [3] $ ("A" "B" "C"); /* categories */
call streaminit(54321); 
do i = 1 to 100;
   j = rand("Table", of prob[*]);
   x = values[j];
   output; 
end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Jun 2017 12:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/364956#M86627</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-07T12:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: set variable equal to a randomly chosen value from a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/365010#M86645</link>
      <description>Always great to learn something new. This is exactly what i was looking for. Thank you.</description>
      <pubDate>Wed, 07 Jun 2017 14:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-equal-to-a-randomly-chosen-value-from-a-list/m-p/365010#M86645</guid>
      <dc:creator>the_sheriff</dc:creator>
      <dc:date>2017-06-07T14:32:23Z</dc:date>
    </item>
  </channel>
</rss>

