<?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 Separate a table by its diagonal line and then combine them back in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722300#M223942</link>
    <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;My task is to split a table into two by its diagonal line. The values in the two tables must then be shifted to the left and one of the table must be flipped horizontally before doing that. With the help of members of this community, I was able to achieve that by the following lines of code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length from $8;
array to {*} r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17;

do _i = 1 to dim(to);
    from = vname(to{_i});
    do _j = 1 to dim(to);
        _x + 1;
        to{_j} = _x;
        end;
    output;
    end;
drop _: ;
format _numeric_ 3.0;
run;

proc print data = have noobs; run;

/*Separate upgrade notch*/
data below;
set have;
array to{*} _numeric_;
_i = _n_;
do _j = _i to 1 by -1;
    to{dim(to)+_j-_i} = to{_j};
    end;
do _j = dim(to)-_i to 1 by -1;
    call missing(to{_j});
    end;
drop _: ;
run;

data upgrade (drop = r1-r17 i);
	set below;
	array u(*) u1-u16;
	array r(*) r1-r17;
	do i = 1 to 16;
		u(0 + i) = r(16 + 1 - i);
	end;
run;

proc print data = upgrade noobs; run;

/*Separate downgrade notch*/
data above;
  set have;
  array COLS [*] r1 - r17;
  do ITER=1 to dim(COLS);
    if ITER=&amp;lt;_N_ then COLS[ITER]=.;
  end;
  output above;
  drop ITER;
run;

data downgrade (drop=r1-r17 j i);
   set above;
   array in r1-r17;
   array out d1-d17;
   j=1;
   do i=1 to 17;
      if in(i) ne ' ' then do;
         out(j)=in(i);
         j+1;
      end;
   end;
drop d17;
run;

proc print data = downgrade noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result is as follow:&lt;/P&gt;&lt;P&gt;Original table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_0-1614392700263.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55257iA20FF878E12A37F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_0-1614392700263.png" alt="Minh2710_0-1614392700263.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resulting tables:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_1-1614392730385.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55258i2555A9086801BDBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_1-1614392730385.png" alt="Minh2710_1-1614392730385.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_2-1614392744867.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55259i0E305BDDBAA81A5C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_2-1614392744867.png" alt="Minh2710_2-1614392744867.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now after I have done all the work with table 2 and 3, I need to combine them back to Table 1 in the exact original order.&lt;/P&gt;&lt;P&gt;If anyone could provide an answer or hint, I would be very much appreciated.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2021 02:28:40 GMT</pubDate>
    <dc:creator>Minh2710</dc:creator>
    <dc:date>2021-02-27T02:28:40Z</dc:date>
    <item>
      <title>Separate a table by its diagonal line and then combine them back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722300#M223942</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;My task is to split a table into two by its diagonal line. The values in the two tables must then be shifted to the left and one of the table must be flipped horizontally before doing that. With the help of members of this community, I was able to achieve that by the following lines of code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length from $8;
array to {*} r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17;

do _i = 1 to dim(to);
    from = vname(to{_i});
    do _j = 1 to dim(to);
        _x + 1;
        to{_j} = _x;
        end;
    output;
    end;
drop _: ;
format _numeric_ 3.0;
run;

proc print data = have noobs; run;

/*Separate upgrade notch*/
data below;
set have;
array to{*} _numeric_;
_i = _n_;
do _j = _i to 1 by -1;
    to{dim(to)+_j-_i} = to{_j};
    end;
do _j = dim(to)-_i to 1 by -1;
    call missing(to{_j});
    end;
drop _: ;
run;

data upgrade (drop = r1-r17 i);
	set below;
	array u(*) u1-u16;
	array r(*) r1-r17;
	do i = 1 to 16;
		u(0 + i) = r(16 + 1 - i);
	end;
run;

proc print data = upgrade noobs; run;

/*Separate downgrade notch*/
data above;
  set have;
  array COLS [*] r1 - r17;
  do ITER=1 to dim(COLS);
    if ITER=&amp;lt;_N_ then COLS[ITER]=.;
  end;
  output above;
  drop ITER;
run;

data downgrade (drop=r1-r17 j i);
   set above;
   array in r1-r17;
   array out d1-d17;
   j=1;
   do i=1 to 17;
      if in(i) ne ' ' then do;
         out(j)=in(i);
         j+1;
      end;
   end;
drop d17;
run;

proc print data = downgrade noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result is as follow:&lt;/P&gt;&lt;P&gt;Original table:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_0-1614392700263.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55257iA20FF878E12A37F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_0-1614392700263.png" alt="Minh2710_0-1614392700263.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resulting tables:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_1-1614392730385.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55258i2555A9086801BDBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_1-1614392730385.png" alt="Minh2710_1-1614392730385.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Minh2710_2-1614392744867.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55259i0E305BDDBAA81A5C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Minh2710_2-1614392744867.png" alt="Minh2710_2-1614392744867.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Now after I have done all the work with table 2 and 3, I need to combine them back to Table 1 in the exact original order.&lt;/P&gt;&lt;P&gt;If anyone could provide an answer or hint, I would be very much appreciated.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 02:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722300#M223942</guid>
      <dc:creator>Minh2710</dc:creator>
      <dc:date>2021-02-27T02:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a table by its diagonal line and then combine them back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722326#M223955</link>
      <description>&lt;P&gt;It is IML thing. If you have SAS/IML .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length from $8;
array to {*} r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17;

do _i = 1 to dim(to);
    from = vname(to{_i});
    do _j = 1 to dim(to);
        _x + 1;
        to{_j} = _x;
        end;
    output;
    end;
drop _: ;
format _numeric_ 3.0;
run;
/*Separate upgrade notch*/
data below;
set have;
array to{*} _numeric_;
_i = _n_;
do _j = _i to 1 by -1;
    to{dim(to)+_j-_i} = to{_j};
    end;
do _j = dim(to)-_i to 1 by -1;
    call missing(to{_j});
    end;
drop _: ;
run;
data upgrade (drop = r1-r17 i);
	set below;
	array u(*) u1-u16;
	array r(*) r1-r17;
	do i = 1 to 16;
		u(0 + i) = r(16 + 1 - i);
	end;
run;
/*Separate downgrade notch*/
data above;
  set have;
  array COLS [*] r1 - r17;
  do ITER=1 to dim(COLS);
    if ITER=&amp;lt;_N_ then COLS[ITER]=.;
  end;
  output above;
  drop ITER;
run;

data downgrade (drop=r1-r17 j i);
   set above;
   array in r1-r17;
   array out d1-d17;
   j=1;
   do i=1 to 17;
      if in(i) ne ' ' then do;
         out(j)=in(i);
         j+1;
      end;
   end;
drop d17;
run;








proc iml;
use  upgrade;
read all var _num_ into up[r=from c=vname];
close;
use  downgrade;
read all var _num_ into down;
close;
want=j(nrow(down),ncol(down)+1,.);

id1=loc(row(want)&amp;lt;col(want));
id2=loc(row(down)+col(down)&amp;lt;=ncol(down)+1);
want[id1]=down[id2];

up=up[,ncol(up):1];
id3=loc(row(want)&amp;gt;col(want));
id4=loc(row(up)+col(up)&amp;gt;ncol(up)+1);
want[id3]=up[id4];

mattrib want r=from l='';
print want;

/*create a output dataset*/
create want from want[r=from];
append from want[r=from];
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="x.jpg" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55263iA19A3D32E7F6161E/image-size/large?v=v2&amp;amp;px=999" role="button" title="x.jpg" alt="x.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 11:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722326#M223955</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-27T11:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a table by its diagonal line and then combine them back</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722356#M223968</link>
      <description>&lt;P&gt;Thanks! It works perfectly.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 19:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-a-table-by-its-diagonal-line-and-then-combine-them-back/m-p/722356#M223968</guid>
      <dc:creator>Minh2710</dc:creator>
      <dc:date>2021-02-27T19:59:51Z</dc:date>
    </item>
  </channel>
</rss>

