<?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: How to randomly swap observations in particular column? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545463#M8030</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267657"&gt;@fongdo&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to do this. Here is one&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input permno state_id;
datalines;
10000 6
10001 35
10002 2
10003 7
10004 5
;

data want(keep=permno state_id);

   array ids{5} _temporary_;
   seed=0;

   do i=1 by 1 until (eof1);
      set have end=eof1;
      ids[i]=state_id;
   end;

   call ranperm(seed, of ids[*]);

   do j=1 by 1 until (eof2);
      set have end=eof2;
      state_id=ids[j];
      output;
   end;

   stop;
run;

proc print data=have;run;
proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Mar 2019 10:52:40 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-03-23T10:52:40Z</dc:date>
    <item>
      <title>How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545460#M8029</link>
      <description>&lt;P&gt;I would like to randomly swap data in column "state_id" (remain "permno") and generate new 1,000 datasets as example below. Could you kindly advise?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Original dataset&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;permno&amp;nbsp; &amp;nbsp; &amp;nbsp; state_id&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;10000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;10001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&lt;/P&gt;&lt;P&gt;10002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;10003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;10004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;New dataset&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;permno&amp;nbsp; &amp;nbsp; &amp;nbsp; state_id&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;10000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;10001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;10002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;10003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;10004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 10:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545460#M8029</guid>
      <dc:creator>fongdo</dc:creator>
      <dc:date>2019-03-23T10:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545463#M8030</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267657"&gt;@fongdo&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways to do this. Here is one&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input permno state_id;
datalines;
10000 6
10001 35
10002 2
10003 7
10004 5
;

data want(keep=permno state_id);

   array ids{5} _temporary_;
   seed=0;

   do i=1 by 1 until (eof1);
      set have end=eof1;
      ids[i]=state_id;
   end;

   call ranperm(seed, of ids[*]);

   do j=1 by 1 until (eof2);
      set have end=eof2;
      state_id=ids[j];
      output;
   end;

   stop;
run;

proc print data=have;run;
proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Mar 2019 10:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545463#M8030</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-23T10:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545466#M8031</link>
      <description>&lt;P&gt;Make a macro to wrap the following code and repeat it 1000 times for your 1000 tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input permno state_id;
datalines;
10000 6
10001 35
10002 2
10003 7
10004 5
;


data x;
 set have(keep=state_id);
 id=rand('uniform');
run;
proc sort data=x;
 by id;
run;
data want;
 merge have(keep=permno) x;
 drop id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Mar 2019 11:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545466#M8031</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-03-23T11:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545513#M8039</link>
      <description>&lt;P&gt;Or put proc surveyselect to the task:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input permno state_id;
datalines;
10000 6
10001 35
10002 2
10003 7
10004 5
;

%let nreps=10;

proc surveyselect data=have(keep=state_id) out=rnd(keep=state_id) 
    samprate=100 method=srs reps=&amp;amp;nreps outorder=random;
run;

proc surveyselect data=have(drop=state_id) out=reps 
    samprate=100 method=srs reps=&amp;amp;nreps;
run;

data want;
set reps;
set rnd;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should be fairly efficient.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 18:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545513#M8039</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-23T18:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545551#M8047</link>
      <description>Thank you very much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;. It works, please advise what does ids {5} mean?</description>
      <pubDate>Sun, 24 Mar 2019 03:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545551#M8047</guid>
      <dc:creator>fongdo</dc:creator>
      <dc:date>2019-03-24T03:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545553#M8048</link>
      <description>Thank you very much Ksharp. It is very helpful.</description>
      <pubDate>Sun, 24 Mar 2019 03:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545553#M8048</guid>
      <dc:creator>fongdo</dc:creator>
      <dc:date>2019-03-24T03:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545554#M8049</link>
      <description>Thank a lot PGStats.</description>
      <pubDate>Sun, 24 Mar 2019 03:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/545554#M8049</guid>
      <dc:creator>fongdo</dc:creator>
      <dc:date>2019-03-24T03:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to randomly swap observations in particular column?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/546205#M8184</link>
      <description>&lt;P&gt;It means that the array &lt;STRONG&gt;ids&amp;nbsp;&lt;/STRONG&gt;has 5 entries.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-randomly-swap-observations-in-particular-column/m-p/546205#M8184</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-26T15:30:52Z</dc:date>
    </item>
  </channel>
</rss>

