Hi,

I have a set:

```
Set i /1*3/;
set j /1*3/;
Set a(i,j) /1.2 2.3 1.3/;
```

How may I get the first, second or third element from set a by ordinality?

I wanted to use

```
ord(a)
```

but it didn’t work with two dimensional set.

Hi,

I have a set:

```
Set i /1*3/;
set j /1*3/;
Set a(i,j) /1.2 2.3 1.3/;
```

How may I get the first, second or third element from set a by ordinality?

I wanted to use

```
ord(a)
```

but it didn’t work with two dimensional set.

How about this?

```
Set i /1*3/;
set j /1*3/;
Set a(i,j) /1.2,2.3,1.3/;
set b(i,j);
b(i,j)$(ord(i) = 3 and ord(j) = 1) = yes;
```

That’s a good idea.

But I need to put it in the loop so that at the second set c element:

```
Set i /1*3/;
set j /1*3/;
Set a(i,j) /1.2,2.3,1.3/;
set b(i,j);
set c/1*3/;
loop (c,
b(i,j) $ (ord(a(i,j))=c) = yes ;
);
```

the b(i,j) result will be 2.3 .

And the code I wrote above does not do this because ord does not work with two-dimensional set.

You can compute your ord value yourself with a loop:

```
Set i /1*3/;
set j /1*3/;
Set a(i,j) /1.2, 2.3, 1.3/;
parameter ordOfA(i,j);
scalar cnt / 0 /;
loop{a(i,j),
cnt = cnt + 1;
ordOfA(i,j) = cnt;
};
display a, ordOfA;
```

Be careful how you use this, though. If you want to do something for the tuples in a(i,j), then it is best to do that directly, not by a loop over something else (say, a loop from 1 to card(a)) and some code to do something for the (i,j) tuples corresponding to the loop variable. The latter approach may work, but it will not be efficient as the data gets large.

-Steve

Thank you. It works.

I understand that directly specifying the (i, j) tuples is more efficient. But this is the only way I can get rid of specifying over 50 of tuples and to avoid mechanical work in the future.

This way you only need an extra loop with the set of 50 elements.