<?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: random observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15038#M1937</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if RANUNI(111) &amp;gt; &lt;STRONG&gt;0.2&lt;/STRONG&gt;; ** adjust this bolded number so it picks apprx 50 obs depending on your source dataset.&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A commonly used function is RANUNI that returns a random variate from a uniform distribution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work"&gt;http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="text-decoration: underline;"&gt;Adding an example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;informat rundate mmddyy10.;&lt;BR /&gt;format rundate mmddyy10.;&lt;BR /&gt;input rundate&amp;nbsp; product $ premthbal curmthbal;&lt;BR /&gt;cards;&lt;BR /&gt;01/05/2012 aaa . 1&lt;BR /&gt;01/05/2012 abc . 2&lt;BR /&gt;01/05/2012 bbb . 3&lt;BR /&gt;01/05/2012 ccc . 4&lt;BR /&gt;01/05/2012 ddd . 5&lt;BR /&gt;01/05/2012 eee . 6&lt;BR /&gt;01/05/2012 fff . 7&lt;BR /&gt;01/05/2012 ggg . 8&lt;BR /&gt;02/05/2012 aaa . 9&lt;BR /&gt;02/05/2012 abc . 8&lt;BR /&gt;02/05/2012 bbb . 7&lt;BR /&gt;02/05/2012 ccc . 6&lt;BR /&gt;02/05/2012 ddd . 5&lt;BR /&gt;02/05/2012 eee . 4&lt;BR /&gt;02/05/2012 fff . 3&lt;BR /&gt;02/05/2012 ggg . 2&lt;BR /&gt;03/05/2012 aaa . 1&lt;BR /&gt;03/05/2012 abc . 2&lt;BR /&gt;03/05/2012 bbb . 3&lt;BR /&gt;03/05/2012 ccc . 4&lt;BR /&gt;03/05/2012 ddd . 5&lt;BR /&gt;03/05/2012 eee . 6&lt;BR /&gt;03/05/2012 fff . 7&lt;BR /&gt;03/05/2012 ggg . 8&lt;BR /&gt;04/05/2012 aaa . 3&lt;BR /&gt;04/05/2012 abc . 2&lt;BR /&gt;04/05/2012 bbb . 1&lt;BR /&gt;04/05/2012 ccc . 3&lt;BR /&gt;04/05/2012 ddd . 2&lt;BR /&gt;04/05/2012 eee . 1&lt;BR /&gt;04/05/2012 fff . 3&lt;BR /&gt;04/05/2012 ggg . 2&lt;BR /&gt;05/05/2012 aaa . 3&lt;BR /&gt;05/05/2012 abc . 2&lt;BR /&gt;05/05/2012 bbb . 1&lt;BR /&gt;05/05/2012 ccc . 3&lt;BR /&gt;05/05/2012 ddd . 2&lt;BR /&gt;05/05/2012 eee . 1&lt;BR /&gt;05/05/2012 fff . 3&lt;BR /&gt;05/05/2012 ggg . 2&lt;BR /&gt;06/05/2012 aaa . 3&lt;BR /&gt;06/05/2012 abc . 2&lt;BR /&gt;06/05/2012 bbb . 1&lt;BR /&gt;06/05/2012 ccc . 3&lt;BR /&gt;06/05/2012 ddd . 2&lt;BR /&gt;06/05/2012 eee . 1&lt;BR /&gt;06/05/2012 fff . 3&lt;BR /&gt;06/05/2012 ggg . 2&lt;BR /&gt;06/05/2012 aaa . 3&lt;BR /&gt;06/05/2012 abc . 2&lt;BR /&gt;06/05/2012 bbb . 1&lt;BR /&gt;06/05/2012 ccc . 3&lt;BR /&gt;07/05/2012 ddd . 2&lt;BR /&gt;07/05/2012 eee . 1&lt;BR /&gt;07/05/2012 fff . 3&lt;BR /&gt;07/05/2012 ggg . 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set test;&lt;BR /&gt;if RANUNI(111) &amp;gt; 0.8;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;02/05/2012 bbb . 7&lt;/P&gt;&lt;P&gt;02/05/2012 ggg . 2&lt;/P&gt;&lt;P&gt;03/05/2012 eee . 6&lt;/P&gt;&lt;P&gt;03/05/2012 fff . 7&lt;/P&gt;&lt;P&gt;03/05/2012 ggg . 8&lt;/P&gt;&lt;P&gt;04/05/2012 aaa . 3&lt;/P&gt;&lt;P&gt;04/05/2012 eee . 1&lt;/P&gt;&lt;P&gt;04/05/2012 fff . 3&lt;/P&gt;&lt;P&gt;05/05/2012 ccc . 3&lt;/P&gt;&lt;P&gt;06/05/2012 ddd . 2&lt;/P&gt;&lt;P&gt;06/05/2012 ccc . 3&lt;/P&gt;&lt;P&gt;07/05/2012 ddd . 2&lt;/P&gt;&lt;P&gt;07/05/2012 eee . 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Feb 2012 18:16:53 GMT</pubDate>
    <dc:creator>Hima</dc:creator>
    <dc:date>2012-02-28T18:16:53Z</dc:date>
    <item>
      <title>random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15034#M1933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have a datset with 1000 observations .my requirement is i want to&amp;nbsp; 50 random observations&amp;nbsp; from the dataset.It must be in random order.How can i get .Can anybody explain.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2012 12:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15034#M1933</guid>
      <dc:creator>rawindar</dc:creator>
      <dc:date>2012-02-27T12:35:35Z</dc:date>
    </item>
    <item>
      <title>random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15035#M1934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More details would be needed for your question. There are so many types of random samples, just simple random sample, such as using ranuni(), or base on certain distributions? with or without replacement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For an official approach, please check out help documents on Proc Surveyselect, which is designed to do the sampling.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2012 13:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15035#M1934</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-02-27T13:02:05Z</dc:date>
    </item>
    <item>
      <title>random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15036#M1935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In addition to what Haikuo suggested, you can always combine methods.&amp;nbsp; E.g., once you select a sample, you can always use ranuni(i) to assign a pseudo random number to each record selected, and then sort the file by that number.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2012 13:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15036#M1935</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-27T13:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15037#M1936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is an example of proc surveyselect. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc surveyselect&lt;/P&gt;&lt;P&gt;data = have&amp;nbsp; out = want&lt;/P&gt;&lt;P&gt;method = srs&lt;/P&gt;&lt;P&gt;&amp;nbsp; n = 50&lt;/P&gt;&lt;P&gt;noprint;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope I have helped you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 17:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15037#M1936</guid>
      <dc:creator>Augusto</dc:creator>
      <dc:date>2012-02-28T17:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15038#M1937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if RANUNI(111) &amp;gt; &lt;STRONG&gt;0.2&lt;/STRONG&gt;; ** adjust this bolded number so it picks apprx 50 obs depending on your source dataset.&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A commonly used function is RANUNI that returns a random variate from a uniform distribution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work"&gt;http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="text-decoration: underline;"&gt;Adding an example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;informat rundate mmddyy10.;&lt;BR /&gt;format rundate mmddyy10.;&lt;BR /&gt;input rundate&amp;nbsp; product $ premthbal curmthbal;&lt;BR /&gt;cards;&lt;BR /&gt;01/05/2012 aaa . 1&lt;BR /&gt;01/05/2012 abc . 2&lt;BR /&gt;01/05/2012 bbb . 3&lt;BR /&gt;01/05/2012 ccc . 4&lt;BR /&gt;01/05/2012 ddd . 5&lt;BR /&gt;01/05/2012 eee . 6&lt;BR /&gt;01/05/2012 fff . 7&lt;BR /&gt;01/05/2012 ggg . 8&lt;BR /&gt;02/05/2012 aaa . 9&lt;BR /&gt;02/05/2012 abc . 8&lt;BR /&gt;02/05/2012 bbb . 7&lt;BR /&gt;02/05/2012 ccc . 6&lt;BR /&gt;02/05/2012 ddd . 5&lt;BR /&gt;02/05/2012 eee . 4&lt;BR /&gt;02/05/2012 fff . 3&lt;BR /&gt;02/05/2012 ggg . 2&lt;BR /&gt;03/05/2012 aaa . 1&lt;BR /&gt;03/05/2012 abc . 2&lt;BR /&gt;03/05/2012 bbb . 3&lt;BR /&gt;03/05/2012 ccc . 4&lt;BR /&gt;03/05/2012 ddd . 5&lt;BR /&gt;03/05/2012 eee . 6&lt;BR /&gt;03/05/2012 fff . 7&lt;BR /&gt;03/05/2012 ggg . 8&lt;BR /&gt;04/05/2012 aaa . 3&lt;BR /&gt;04/05/2012 abc . 2&lt;BR /&gt;04/05/2012 bbb . 1&lt;BR /&gt;04/05/2012 ccc . 3&lt;BR /&gt;04/05/2012 ddd . 2&lt;BR /&gt;04/05/2012 eee . 1&lt;BR /&gt;04/05/2012 fff . 3&lt;BR /&gt;04/05/2012 ggg . 2&lt;BR /&gt;05/05/2012 aaa . 3&lt;BR /&gt;05/05/2012 abc . 2&lt;BR /&gt;05/05/2012 bbb . 1&lt;BR /&gt;05/05/2012 ccc . 3&lt;BR /&gt;05/05/2012 ddd . 2&lt;BR /&gt;05/05/2012 eee . 1&lt;BR /&gt;05/05/2012 fff . 3&lt;BR /&gt;05/05/2012 ggg . 2&lt;BR /&gt;06/05/2012 aaa . 3&lt;BR /&gt;06/05/2012 abc . 2&lt;BR /&gt;06/05/2012 bbb . 1&lt;BR /&gt;06/05/2012 ccc . 3&lt;BR /&gt;06/05/2012 ddd . 2&lt;BR /&gt;06/05/2012 eee . 1&lt;BR /&gt;06/05/2012 fff . 3&lt;BR /&gt;06/05/2012 ggg . 2&lt;BR /&gt;06/05/2012 aaa . 3&lt;BR /&gt;06/05/2012 abc . 2&lt;BR /&gt;06/05/2012 bbb . 1&lt;BR /&gt;06/05/2012 ccc . 3&lt;BR /&gt;07/05/2012 ddd . 2&lt;BR /&gt;07/05/2012 eee . 1&lt;BR /&gt;07/05/2012 fff . 3&lt;BR /&gt;07/05/2012 ggg . 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set test;&lt;BR /&gt;if RANUNI(111) &amp;gt; 0.8;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;02/05/2012 bbb . 7&lt;/P&gt;&lt;P&gt;02/05/2012 ggg . 2&lt;/P&gt;&lt;P&gt;03/05/2012 eee . 6&lt;/P&gt;&lt;P&gt;03/05/2012 fff . 7&lt;/P&gt;&lt;P&gt;03/05/2012 ggg . 8&lt;/P&gt;&lt;P&gt;04/05/2012 aaa . 3&lt;/P&gt;&lt;P&gt;04/05/2012 eee . 1&lt;/P&gt;&lt;P&gt;04/05/2012 fff . 3&lt;/P&gt;&lt;P&gt;05/05/2012 ccc . 3&lt;/P&gt;&lt;P&gt;06/05/2012 ddd . 2&lt;/P&gt;&lt;P&gt;06/05/2012 ccc . 3&lt;/P&gt;&lt;P&gt;07/05/2012 ddd . 2&lt;/P&gt;&lt;P&gt;07/05/2012 eee . 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 18:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15038#M1937</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2012-02-28T18:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15039#M1938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC SURVEYSELECT will do a good job, but will not return the observations in random order. As Art pointed out, you will need extra work to shuffle the selected observations. For simple random sampling, you can get the same result with the following procedure. Assuming your observations are in dataset &lt;SPAN style="text-decoration: underline;"&gt;have&lt;/SPAN&gt;, the following will select exactly 50 observations without replacement, ordered randomly in dataset &lt;SPAN style="text-decoration: underline;"&gt;want&lt;/SPAN&gt; :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Writes a warning about terminating early */&lt;/P&gt;&lt;P&gt;proc sql outobs=50;&lt;BR /&gt;create table want as&lt;BR /&gt;select *, rand("UNIFORM") as _randomNumber from have&lt;BR /&gt;order by calculated _randomNumber;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 20:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15039#M1938</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-02-28T20:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15040#M1939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PGStats - I tested the code and for some reason it was pulling all the observations. Can you verify? This is what I came up with from your code and pulling the 50 observations correctly and randomly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set test;&lt;BR /&gt;randomNumber = RAND("UNIFORM");&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=want;&lt;BR /&gt;by randomNumber; &lt;BR /&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want1;&lt;BR /&gt;set want (firstobs=1 obs = 50);&lt;BR /&gt;drop randomNumber;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print data=want1; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 20:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15040#M1939</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2012-02-28T20:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: random observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15041#M1940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I just changed my proposal. Sorry about the other version. OBS= only works for input datasets, it doesn't work with output datasets. -PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 20:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-observations/m-p/15041#M1940</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-02-28T20:20:57Z</dc:date>
    </item>
  </channel>
</rss>

