<?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: re arranging rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446441#M112005</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input ac 3. id  rc $2.;
datalines;
12 45 qq
78 0 da
56 34 ad
45 56 gh
34 78 cc
;
run;
proc sql;
create table ancient as
 select * from aa 
  where ac not in (select id from aa);
run;
data want;
if _n_=1 then do;
if 0 then set aa;
  dcl hash h(dataset:'aa');
   h.definekey('ac');
   h.definedata(all:'y');
   h.definedone();
end;
set ancient;
output;
do while(h.find(key:id)=0);
 output;
end;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice: there is only one to one match .&lt;/P&gt;</description>
    <pubDate>Sat, 17 Mar 2018 13:34:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-03-17T13:34:29Z</dc:date>
    <item>
      <title>re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446331#M111964</link>
      <description>&lt;P&gt;I am having data&amp;nbsp;&lt;/P&gt;&lt;P&gt;like below&lt;/P&gt;&lt;P&gt;Variable RC is continued by other 10 more variables but main goal is to re arrange AC and ID please let me know&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;looking to re arrange rows not variable arrangement&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data aa;&lt;BR /&gt;input ac 3. id&amp;nbsp;3. rc $2.;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;12 45 qq&lt;BR /&gt;78 0 da&lt;BR /&gt;56 34 ad&lt;BR /&gt;45 56 gh&lt;BR /&gt;34 78 cc&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wanted output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;ac id rc&lt;BR /&gt;12 45 qq&lt;BR /&gt;45 56 gh&lt;BR /&gt;56 34 ad&lt;BR /&gt;34 78 cc&lt;BR /&gt;78 0 da&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 20 Million records using sas 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;suggest me without using Arrays and hash if possible (please suggest in Proc sql ) or other methods&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Mar 2018 05:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446331#M111964</guid>
      <dc:creator>bobi</dc:creator>
      <dc:date>2018-03-18T05:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446338#M111967</link>
      <description>&lt;P&gt;What are you trying to re-arrange, variables or rows?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If variables are needed to rearrange use RETAIN statement and for rows use PROC SORT&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446338#M111967</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-16T20:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446340#M111969</link>
      <description>&lt;P&gt;Please explicitly and in great detail describe how we derive the order of the output.&lt;/P&gt;
&lt;P&gt;It appears that you want id on one row to be followed by an AC value on the next.&lt;/P&gt;
&lt;P&gt;But how do you handle multiple values of AC that would match such as:&lt;/P&gt;
&lt;P&gt;12 45 qq&lt;/P&gt;
&lt;P&gt;78 0 da&lt;/P&gt;
&lt;P&gt;56 34 ad&lt;/P&gt;
&lt;P&gt;45 56 gh&lt;/P&gt;
&lt;P&gt;34 78 cc&lt;/P&gt;
&lt;P&gt;45 33 zz&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;Please do not tell me that in 20 million rows that will not occur (unless your AC and ID variables have many more digits).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what happens&amp;nbsp;if you have an ID with NO matching AC?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If RC does not play any role in the exercise than don't include it. If it does have some importance explain how it and the other variables might affect the order.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446340#M111969</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-16T20:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446342#M111971</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input ac 3. id  rc $2.;
datalines;
12 45 qq
78 0 da
56 34 ad
45 56 gh
34 78 cc
;
run;

data want;
if _n_=1 then do;
if 0 then set aa;
  dcl hash h(dataset:'aa');
   h.definekey('ac');
   h.definedata('ac','id','rc');
   h.definedone();
end;
set aa;
retain _id;
if _n_&amp;gt;1 then do;
if h.find(key:_id)=0;
end;
_id=id;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446342#M111971</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-16T20:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446441#M112005</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;
input ac 3. id  rc $2.;
datalines;
12 45 qq
78 0 da
56 34 ad
45 56 gh
34 78 cc
;
run;
proc sql;
create table ancient as
 select * from aa 
  where ac not in (select id from aa);
run;
data want;
if _n_=1 then do;
if 0 then set aa;
  dcl hash h(dataset:'aa');
   h.definekey('ac');
   h.definedata(all:'y');
   h.definedone();
end;
set ancient;
output;
do while(h.find(key:id)=0);
 output;
end;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice: there is only one to one match .&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 13:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446441#M112005</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-17T13:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446672#M112114</link>
      <description>&lt;P&gt;RC is the most important key for my analysis, AC is current ID and RC is old ID at a instance(date)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AC RC date&lt;/P&gt;&lt;P&gt;11&amp;nbsp; 22 today&lt;/P&gt;&lt;P&gt;22 33&amp;nbsp; yesterday&lt;/P&gt;&lt;P&gt;33 44&amp;nbsp;so on&lt;/P&gt;&lt;P&gt;44 55&amp;nbsp;so on&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;55 0&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;so on&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;at the beginning I have 55 and 0 initially&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;55 changed to 44 --33 -- 22 finally to 11&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes If I sort by date I can get it but if all changes&amp;nbsp; happens on same day I cannot track it if it is unsorted&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please all the numbers are not in sequence like 11 --55 its random number&amp;nbsp; I have to track&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 04:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446672#M112114</guid>
      <dc:creator>bobi</dc:creator>
      <dc:date>2018-03-19T04:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446710#M112130</link>
      <description>&lt;P&gt;Here is a solution using SET with KEY=. I assume that you want to start with the first record, keep buildng the thread from there, and when the thread stops, read the&amp;nbsp;next unused record:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa;                           
input ac id  rc $;                 
datalines;                         
12 45 qq                           
78 0 da                            
56 34 ad                           
45 56 gh                           
34 78 cc                           
;                                  
run;                               
                                   
data temp(index=(ac));
  set aa;
run;

data want temp;
  set temp(cntllev=rec);
  do until(0);
    modify temp(cntllev=rec) key=ac;
    if _iorc_ then leave;
    output want;
    remove temp;
    ac=id;
    end;
  _error_=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unlike the solution proposed by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, this solution is able to accomodate more than one thread, and unlike the solution proposed by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;, if you have two records with the same AC, it is possible for the second one to start a new thread.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 10:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446710#M112130</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-19T10:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446875#M112196</link>
      <description>&lt;P&gt;please suggest using Proc sql&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For hash object I am getting following error&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Hash object added xxxxx items when memory failure occurred.&lt;BR /&gt;FATAL: Insufficient memory to execute DATA step program. Aborted during the EXECUTION phase.&lt;BR /&gt;ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 17:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446875#M112196</guid>
      <dc:creator>bobi</dc:creator>
      <dc:date>2018-03-19T17:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446962#M112219</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3542"&gt;@bobi&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;RC is the most important key for my analysis, AC is current ID and RC is old ID at a instance(date)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AC RC date&lt;/P&gt;
&lt;P&gt;11&amp;nbsp; 22 today&lt;/P&gt;
&lt;P&gt;22 33&amp;nbsp; yesterday&lt;/P&gt;
&lt;P&gt;33 44&amp;nbsp;so on&lt;/P&gt;
&lt;P&gt;44 55&amp;nbsp;so on&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;55 0&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;so on&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Supplying an actual date in the initial question would have helped a whole lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes If I sort by date I can get it but if all changes&amp;nbsp; happens on same day I cannot track it if it is unsorted&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is there any guarantee that the order you have is correct then?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 22:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/446962#M112219</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-19T22:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: re arranging rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/447061#M112237</link>
      <description>&lt;P&gt;No. SQL can't do it due to don't know how many hierarchy/strata it is .&lt;/P&gt;
&lt;P&gt;How big size of your table is it ?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 12:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-arranging-rows/m-p/447061#M112237</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-20T12:18:02Z</dc:date>
    </item>
  </channel>
</rss>

