problem in if statement

hello, I am new to GAMS and I have started coding in GAMS with some small problems. Currently, in one problem I am using ‘if’ statement as follow:
if (a(t) <=b(t),
p(i,t)=a(t);
else
p(i,t)=b(t);
);
in this code error_119(related to primary number) is occurred.
Thanks in advance for help in future.

Hi

You have to loop over t as Gams doesn’t allow this kind of direct assignment in an if-statement:

loop(t,
	if (a(t) <=b(t),
		p(i,t)=a(t);
	else
		p(i,t)=b(t);
	);
);

You could do this, however using the dollar sign

p(i,t)$(a(t) < b(t)) = a(t);
p(i,t)$(a(t) > b(t)) = b(t);

p(i,t)$… is pronounced as p(i,t) such that my condition is equal to

Cheers
Renger