|
Reordering set order in output |
Top Previous Next |
|
Sometimes one needs to reorder the data. Here I do it using an order set and put files in the example reorder.gms
Set I /1*4/; set j /a1*a3 a4 this is element 4 a5 has a crummy name/; set newnames(j) /a1 nuts a2 bolts a3 cars a4 trucks a5/; table data(i,j) data to be put a1 a2 a3 a4 a5 1 11 12 2 14 15 3 1 1 4 2 4.10 ; put // 'Data as originally ordered' / @29 loop(j,put newnames.te(j):12 ' '); put /; loop(i, put i.te(i):20 ' '; loop(j,if((not sameas(j,'a4')),put data(i,j):12:0 ' ';); if(sameas(j,'a4'),put data(i,j):12:4 ' ';)); put /); set iwantord /o1*o100/; set ordit(iwantord,j) / o1.a4,o2.(a1,a3),o3.a4/; put // 'Data as reordered' / @29 loop(ordit(iwantord,j),put newnames.te(j):12 ' ');put /; loop(i, put i.te(i):20 ' ' loop(ordit(iwantord,j), if((not sameas(j,'a4')),put data(i,j):12:0 ' ';); if(sameas(j,'a4'),put data(i,j):12:4 ' ';));put /);
Data as originally ordered
Nuts Bolts Cars Trains a5 1 11 12 0 0.0000 0 2 0 0 14 15.0000 0 3 1 0 0 0.0000 1 this one is 4 0 2 0 4.1000 0
Data as reordered (note I dropped a5 on purpose)
Trains Nuts Cars Trains 1 0.0000 11 0 0.0000 2 15.0000 0 14 15.0000 3 0.0000 1 0 0.0000 this one is 4 4.1000 0 0 4.1000 |