<?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 based on variable in column 1 in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24547#M860</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID othervar $6.; &lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1001 a &lt;/P&gt;&lt;P&gt;1001 b &lt;/P&gt;&lt;P&gt;1001 c &lt;/P&gt;&lt;P&gt;1004 d &lt;/P&gt;&lt;P&gt;1004 dd &lt;/P&gt;&lt;P&gt;1005 e &lt;/P&gt;&lt;P&gt;1006 f &lt;/P&gt;&lt;P&gt;1006 g &lt;/P&gt;&lt;P&gt;1006 h&lt;/P&gt;&lt;P&gt;1006 i ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*strip down to unique ids*/ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=temp1 nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by ID; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*generate uniform random variable for each unique ID*/ &lt;/P&gt;&lt;P&gt;/*I'm sure PROC SURVEYSELECT would be a good choice here if you want a fixed number of IDs, but this is a little more general, and a lot less precise*/ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set temp1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ranno=ranuni(1); &lt;/P&gt;&lt;P&gt;/*so that this is repeatable, I specified a fixed seed*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranno&amp;gt;0.3;&lt;/P&gt;&lt;P&gt;/*You'll need to fiddle with this so that you get approximately the right number in your sample*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep ID ranno;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as select a.* from have a, temp2 b where a.ID=b.ID;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should provide a good start...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited to improve readability.&amp;nbsp; I hope this works.&amp;nbsp; Cutting and pasting from the SAS editor doesn't work so nicely&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Jul 2011 12:07:16 GMT</pubDate>
    <dc:creator>SteveDenham</dc:creator>
    <dc:date>2011-07-01T12:07:16Z</dc:date>
    <item>
      <title>Random selection based on variable in column 1</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24546#M859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to do a random selection based on the numeric variables (IDs) in column 1. Column 1 has a set of numbers which represent IDs. These ID numbers are repeated many times over as entries are associated with the ID numbers in column 1. I want to randomly select based on these ID numbers but then make sure we pick up all the transactions for that ID so we have a full set of entrries for the ID number randomly selected. Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Other fields etc&lt;/P&gt;&lt;P&gt;1001&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;1001&lt;/P&gt;&lt;P&gt;1001&lt;/P&gt;&lt;P&gt;1004&lt;/P&gt;&lt;P&gt;1004&lt;/P&gt;&lt;P&gt;1005&lt;/P&gt;&lt;P&gt;1006&lt;/P&gt;&lt;P&gt;1006&lt;/P&gt;&lt;P&gt;1006&lt;/P&gt;&lt;P&gt;1006&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to make sure if 1006 is selected randomly then we get all the rows/entries for ID 1006 in the random output file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Jul 2011 11:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24546#M859</guid>
      <dc:creator>Dave</dc:creator>
      <dc:date>2011-07-01T11:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Random selection based on variable in column 1</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24547#M860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID othervar $6.; &lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1001 a &lt;/P&gt;&lt;P&gt;1001 b &lt;/P&gt;&lt;P&gt;1001 c &lt;/P&gt;&lt;P&gt;1004 d &lt;/P&gt;&lt;P&gt;1004 dd &lt;/P&gt;&lt;P&gt;1005 e &lt;/P&gt;&lt;P&gt;1006 f &lt;/P&gt;&lt;P&gt;1006 g &lt;/P&gt;&lt;P&gt;1006 h&lt;/P&gt;&lt;P&gt;1006 i ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*strip down to unique ids*/ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have out=temp1 nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by ID; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*generate uniform random variable for each unique ID*/ &lt;/P&gt;&lt;P&gt;/*I'm sure PROC SURVEYSELECT would be a good choice here if you want a fixed number of IDs, but this is a little more general, and a lot less precise*/ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set temp1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ranno=ranuni(1); &lt;/P&gt;&lt;P&gt;/*so that this is repeatable, I specified a fixed seed*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ranno&amp;gt;0.3;&lt;/P&gt;&lt;P&gt;/*You'll need to fiddle with this so that you get approximately the right number in your sample*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep ID ranno;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as select a.* from have a, temp2 b where a.ID=b.ID;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should provide a good start...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited to improve readability.&amp;nbsp; I hope this works.&amp;nbsp; Cutting and pasting from the SAS editor doesn't work so nicely&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Jul 2011 12:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24547#M860</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2011-07-01T12:07:16Z</dc:date>
    </item>
    <item>
      <title>Random selection based on variable in column 1</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24548#M861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks. This is my first attempt with SAS and if possible would like to know if this is doable via dialog boxes. Here is a copy of the log from the dialog box using strata based on the ID. Is there a small adjustment to be made to this log that would make it work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;/* -------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code generated by SAS Task&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Generated on: Saturday, July 02, 2011 at 4:15:00 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; By task: Random Sample&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Input data: WORK.Hfile1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Server: Local&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: green;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------------------------------------------------------------- */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;%&lt;STRONG&gt;&lt;EM&gt;_eg_conditional_dropds&lt;/EM&gt;&lt;/STRONG&gt;(WORK.SORTTempTableSorted, WORK.RANDRandomSampleHfile1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;SORT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;DATA&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=WORK.Hfile1()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;OUT&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=WORK.SORTTempTableSorted;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; ID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;SURVEYSELECT&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;DATA&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=WORK.SORTTempTableSorted&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;OUT&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=WORK.RANDRandomSampleHfile1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;METHOD&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=SRS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;RATE&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;%SYSEVALF&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;&lt;STRONG style="color: teal; background-color: white; font-family: 'Courier New';"&gt;10&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;/&lt;/SPAN&gt;&lt;STRONG style="color: teal; background-color: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;STRATA&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; ID / &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue;"&gt;ALLOC&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;=PROP;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background-color: white; font-family: 'Courier New';"&gt;QUIT&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black;"&gt;%&lt;STRONG&gt;&lt;EM&gt;_eg_conditional_dropds&lt;/EM&gt;&lt;/STRONG&gt;(WORK.SORTTempTableSorted);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Jul 2011 20:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Random-selection-based-on-variable-in-column-1/m-p/24548#M861</guid>
      <dc:creator>Dave</dc:creator>
      <dc:date>2011-07-02T20:22:20Z</dc:date>
    </item>
  </channel>
</rss>

