Referencing n-th element of a subset

Hi everyone, I am having trouble referencing the n-th element of a subset. One example is the following:

Set
i /a1*a20/
ii(i) /a2, a7, a13, a15, a18/
;

I want to write a constraint for ii = {a7,a13,a15} which starts from the 2nd element of ii to the 2nd to last element.

Is there a syntax on GAMS for this purpose?

Thank you!

.pos (https://www.gams.com/41/docs/UG_SetDefinition.html#UG_SetDefinition_SetAttributes) does the trick (even for dynamic sets):

Set
i /a1*a20/
ii(i) /a2, a7, a13, a15, a18/
iii(i) '2nd element of ii to the 2nd to last element'
;
iii(ii) = ii.pos>=2 and ii.pos<=card(ii)-1;
display iii;

this gives you:

----      7 SET iii  2nd element of ii to the 2nd to last element
a7 ,    a13,    a15

-Michael

Thank you, Michael. This solution works for a set with one index. What if we have sets with 2 indices.

Set
i /a1*a20/
n /n1, n2/
ii(n, i) /n1.a2, n1.a7, n1.a13, n1.a15, n1.a18, n2.a3, n2.a5, n2.a20/
iii(n, i) '2nd element of ii to the 2nd to last element'
;

In this case, how do I get iii(‘n2’, i) – 2nd element of ii to the 2nd to last element when n=n2?