15 Oct 10 4:58
This is look-ahead code.
The ++ performs the same operation as +. Some programmers prefer to use this syntax on sum statements so that it stands out. Consequently _n_ +_n_ < n will work just as well.
The second part of the expression: _n_<n resolves to a boolean value (i.e 1 or 0). If _n_ is not the last row, it will increment it by 1. I prefer to write it as _n_+(_n_<n) to highlight this behaviour.
As you may be aware, in SAS reading rows behind is straight forward using the lag function, however reading rows ahead is not so simple. This is why in this code you have two set statements. The first is to read the row ahead(starting at row 2 and ending on the last row), and the second set statement is to read the rows as normal (staring at row 1 ending at the last row).
If you try to read past the last row, SAS throws an ERROR, that's why it's important to keep track of what row is being read.
We can replicate this behaviour on the sashelp.class dataset which will be useful for others to see this behaviour in action.
data class ;
set sashelp.class point=_n_ ;
name2 = name;
set sashelp.class nobs=n end=end;
There are of course other ways to do this, which is discussed in more depth here: http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back