It appears as if your a variable defines the order of the observations. If this is the case I would sort the data in descending order of A and then use the lag function in a data step to lag the first obs to the second, second to third etc.
If A does not define the order of the observations I would probably create a variable based on the obs number in a data step first (use the _n_ variable)
Let me know if you need further explantion
input a b;
proc sort ; by descending obsnum;
newcol = lag(b);
proc sort data = two; by obsnum; * this gets in back in the original order;
Your code in the last post does not really make sense... My interpretation of your question is that LAP solved it for you. Since have no variable which naturally holds the order, it is created temporarily (obsnum). Please read his/hers post again more carefully.
If your not concerned about the final order of the rows, try this:
set IN (firstobs=2) end=_EOF ; /* first set starts at 2nd row */
if _EOF then do; /* deals with last row */
C=B; /* stores value of B into C */
set IN; /* second set starts at 1st row */
this results in:
a b c
1 23 15
2 15 45
3 45 55
5 67 0
4 55 67
result is as expected, but the last row positions is switched with the previous.
Again. Thanks a lot. I used this lag() function. I did not now that this function exists before. I tried to search “help” for some function to do my task. I used wrong keywords all the times. With this function it took me 5 sec. to calculate what I need.
Now I am wandering if it is possible to find a list of all functions SAS can use? Well , of course there are thousands of them but one can scroll down thought the list and find the appropriate function he/she needs.