Thanks PGStats for your answer,
In _OROPTMODEL_ variable there is also optimal value (among other), but I have an optimal value also in my local variable y.
Your hint about looking at _OROPTMODEL_ documentation lead me to "SYMGET" and "CALL SYMPUT". The last one turned out to be a needed element.
Below, is a corrected version of my code - just for someone who would have similar problem with assignment of local variable to global variable.
%LET OptimalValue=0;
%macro outer;
%firstmodel(8);
*other code;
%put "opt in outer =" &OptimalValue;
%mend outer;
%macro firstmodel(i);
proc optmodel;
num y;
var x;
max f=x;
con c1: x<=&i;
solve;
y=f;
put y;
call symput('OptimalValue',trim(left(put(y,8.))));
%put "opt in first model=" &OptimalValue;
quit;
%mend firstmodel;
%outer;