Consider the following example: data have; x=1;output; x=2;output; x=3;output; run; data want; set have; retain x; run; what happens in sas is: Reading the first observation --> x=1 Reading the second observation before set statement x=1 (which happens because of the set statement, retain statement being useless in my example, is only to mimic your situation) Reading the second observation after set statement x=2 Reading the third observation before set statement x=2 Reading the third observation after set statement x=3 So because the variable have the same name the retain does nothing. Instead consider the following example: data have; x=1;output; x=2;output; x=3;output; run; data want; set have; retain y; y=x; run; what happens in sas is: Reading the first observation --> x=1, y=1 Reading the second observation before set statement x=1 (because of the set statement), y=1 (because of retain statement) Reading the second observation after set statement and before y=x assignment x=2, y=1 Reading the second observation after set statement and after y=x assignment x=2, y=2 Reading the third observation before set statement x=2 (because of the set statement), y=2 (because of retain statement) Reading the third observation after set statement and before y=x assignment x=3, y=2 Reading the third observation after set statement and after y=x assignment x=3, y=3
... View more