<?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: Randomly reorder rows within a group in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330341#M17455</link>
    <description>&lt;P&gt;Thank you Laurie. I didn't know you could order rows based on variables that are not in the select clause.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2017 22:18:26 GMT</pubDate>
    <dc:creator>spirto</dc:creator>
    <dc:date>2017-02-06T22:18:26Z</dc:date>
    <item>
      <title>SURVEYSELECT: Randomly reorder rows within a group</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330027#M17429</link>
      <description>&lt;P&gt;Hi everyone, is it possible to use proc surveyselect to randomly reorder my rows of data within a group variable. For example, in the code below I would like to randomly reorder the rows of data within each site&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input site $ sub $ x1 x2 x3;
datalines;
A A1 1 1 1
A A2 2 2 2
A A3 3 3 3
B B1 4 4 4
C C1 5 5 5
C C2 6 6 6
D D1 7 7 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and i would like get a output data set that looks like this for example.&lt;/P&gt;
&lt;P&gt;A A3 3 3 3&lt;/P&gt;
&lt;P&gt;A A1 1 1 1&lt;BR /&gt;A A2 2 2 2&lt;BR /&gt;B B1 4 4 4&lt;/P&gt;
&lt;P&gt;C C2 6 6 6&lt;BR /&gt;C C1 5 5 5&lt;BR /&gt;D D1 7 7 7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using this code but it did not randomly order the rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyselect data=have out=want samprate=1;
    strata site;
    id _ALL_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. I was able to accomplish this using ranuni and then sorting but I would be prefer to use surveyselect in order to create many replicates and run a simulation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; set have; r=ranuni(0); run;
proc sort data=have out=want; by site r; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2017 15:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330027#M17429</guid>
      <dc:creator>spirto</dc:creator>
      <dc:date>2017-02-06T15:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly reorder rows within a group</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330042#M17430</link>
      <description>&lt;P&gt;I'll leave hints on how to use&amp;nbsp;&lt;EM&gt;surveyselect&lt;/EM&gt; to people who know what they're talking about. I'm the last one to ask!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you do have to go down the sorting route with&amp;nbsp;&lt;EM&gt;ranuni&lt;/EM&gt;, you&amp;nbsp;&lt;EM&gt;can&lt;/EM&gt; do it in a single pass:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
   select *
     from have
    order by site, ranuni(0);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get:&lt;/P&gt;
&lt;DIV id="sasLogNote3_1486326299980" class="sasNote"&gt;NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1486326299980" class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;But&amp;nbsp;that's the only downside. I've used this method over millions of rows and it's still very&amp;nbsp;efficient.&lt;/DIV&gt;</description>
      <pubDate>Sun, 05 Feb 2017 20:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330042#M17430</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-05T20:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly reorder rows within a group</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330341#M17455</link>
      <description>&lt;P&gt;Thank you Laurie. I didn't know you could order rows based on variables that are not in the select clause.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 22:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SURVEYSELECT-Randomly-reorder-rows-within-a-group/m-p/330341#M17455</guid>
      <dc:creator>spirto</dc:creator>
      <dc:date>2017-02-06T22:18:26Z</dc:date>
    </item>
  </channel>
</rss>

