<?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 selection of subjects in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57877#M12559</link>
    <description>Ignore this post.

Message was edited by: Patrick</description>
    <pubDate>Thu, 30 Oct 2008 07:32:19 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2008-10-30T07:32:19Z</dc:date>
    <item>
      <title>random selection of subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57875#M12557</link>
      <description>hi all,&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset  with multiple subjects, and each subjects have multiple entries. Now I need to select a subset of subjects and all entries of each selected subject will be kept in my output. &lt;BR /&gt;
Eg, I have the 'subject' variable in the original dataset look like: &lt;BR /&gt;
1111 2 2 2  3 3   4444 555555&lt;BR /&gt;
If I need to get 2 random subjects  and their corresponding entries in the output file, say subject 1 and 4, then the output file should have the 'subject' variable with&lt;BR /&gt;
1111 4444.&lt;BR /&gt;
&lt;BR /&gt;
 How can I achieve it in SAS? Thanks!</description>
      <pubDate>Wed, 29 Oct 2008 18:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57875#M12557</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-29T18:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: random selection of subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57876#M12558</link>
      <description>You can use ranuni(0) function to generate a random number and then POINT= option in a SET statement.&lt;BR /&gt;
data random(keep =subject);                                               sampsize=2;                                              do i=1 to sampsize;                                                    pickit=ceil(ranuni(11111)*totobs);                                                    set work.table point=pickit nobs=totobs;                                             output;                                                  end;                                                     stop;                                                    run;</description>
      <pubDate>Wed, 29 Oct 2008 20:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57876#M12558</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-29T20:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: random selection of subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57877#M12559</link>
      <description>Ignore this post.

Message was edited by: Patrick</description>
      <pubDate>Thu, 30 Oct 2008 07:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57877#M12559</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-30T07:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: random selection of subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57878#M12560</link>
      <description>First reorganise your data in a way that you have one subject per observation.&lt;BR /&gt;
&lt;BR /&gt;
The following code then creates a sample with a given number of observations, selects all observations with the same likelyhood and doesn't select twice the same observation. The code is as provided by SAS.&lt;BR /&gt;
&lt;BR /&gt;
 data work.rsubset(drop=obsleft sampsize); &lt;BR /&gt;
 sampsize=10; &lt;BR /&gt;
 obsleft=totobs; &lt;BR /&gt;
 do while(sampsize&amp;gt;0); &lt;BR /&gt;
 pickit+1; &lt;BR /&gt;
 if ranuni(0) lt sampsize / obsleft then do; &lt;BR /&gt;
 set sasuser.revenue point=pickit &lt;BR /&gt;
 nobs=totobs; &lt;BR /&gt;
 output; &lt;BR /&gt;
 sampsize=sampsize-1; &lt;BR /&gt;
 end; &lt;BR /&gt;
 obsleft=obsleft-1; &lt;BR /&gt;
 end; &lt;BR /&gt;
 stop; &lt;BR /&gt;
 run; &lt;BR /&gt;
&lt;BR /&gt;
Vasile: Your code could pick the same observation more than once (i.e. ranuni returns once 0.8... and once 0.7....).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick

Message was edited by: Patrick</description>
      <pubDate>Thu, 30 Oct 2008 07:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57878#M12560</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-30T07:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: random selection of subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57879#M12561</link>
      <description>Patrick, your observation is correct, thanks.</description>
      <pubDate>Thu, 30 Oct 2008 10:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/random-selection-of-subjects/m-p/57879#M12561</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-30T10:59:54Z</dc:date>
    </item>
  </channel>
</rss>

