You can build up a set pos(p,x,a) that gives you the location a (in your vector) for the xth occurrence of the number p and with that you easily access the location of the ith location of a value. If you change c then the set pos becomes outdated and needs to be recalculated. So I you you just access a single ith occurrence of a value to just change it then this is not much of a help over the trivial solution (implemented in macro change). This pos-solution assumes that the values of c come from small set (I used an alias to A). Anyway, here is the code.
-Michael
Code: Select all
Set A/1*9/;
Parameter c(A) /1 1,2 2,3 1,4 3,5 1,6 1,7 3,8 3,9 2/;
alias (a,p,x);
set pos(p,x,a);
parameter n(p); n(p)=0;
loop((a,p,x)$(sameas('1',x) and c(a)=p.val),
pos(p,x+n(p),a) = yes;
n(p) = n(p)+1;
);
option pos:0:0:1, c:0;
display pos;
display c;
c(a)$pos('1','3',a) = 4;
display c;
scalar cnt;
$macro change(v,p,nv) cnt=0; loop(a, cnt=cnt+(c(a)=v); if (cnt=p, c(a)=nv; break;))
* Undo previous change
change(4,1,1);
display c;
* Redo previous change
change(1,3,4);
display c;