thanks for your help , the proposed code give me the following result age country region x want y 1 FR Europe 0,5 1 1 2 FR Europe 0,6 0,5 3 FR Europe 0,7 0,2 4 FR Europe 0,8 0,06 5 FR Europe 0,9 0,012 1 US America 0,1 1 1 2 US America 0,2 0,9 3 US America 0,3 0,72 4 US America 0,4 0,504 5 US America 0,5 0,3024 data want;
set have;
by country region age;
y=lag(y)*(1-lag(x));
if first.country then y=1;
run; when i tried retain as below i've got wrong result comparing to column want age country region x want y 1 FR Europe 0,5 1 1 2 FR Europe 0,6 0,5 0,5 3 FR Europe 0,7 0,2 0,4 4 FR Europe 0,8 0,06 0,15 5 FR Europe 0,9 0,012 0,08 1 US America 0,1 1 1 2 US America 0,2 0,9 0,072 3 US America 0,3 0,72 0,8 4 US America 0,4 0,504 0,0504 5 US America 0,5 0,3024 0,48 data want;
set have;
by country region age;
retain y 1;
y=lag(y)*(1-lag(x));
if first.country then y=1;
run;
... View more