03-02-2017 05:33 PM
Please, I would like to have the results of lag by retain function only[ i.e: w_1=lag(w), ...]
I want to use only "retain"
03-02-2017 06:44 PM
If your data is contained in a SAS data set, you can take advantage of the fact that all such variables are automatically retained. Assuming that you are working with numeric variables, you could use:
If you want to lag for a few observations, you have to explicitly retain those variables that are not coming from a SAS data set. For example:
w_3 = w_2;
w_2 = w_1;
w_1 = w;
retain w_1 w_2;
The trick is to copy values before the SET statement replaces W.