reading next observation's value in current observation

后端 未结 3 1170
梦如初夏
梦如初夏 2020-12-08 12:26

I\'ve a dataset called \'input\' with the following observations

ID Salary
10 1000
20 2000
30 3000
40 4000

I need an output dataset with

3条回答
  •  爱一瞬间的悲伤
    2020-12-08 12:51

    There's no direct way to do this in a data step. There's two approaches you can use:

    Option 1: Sort in reverse, use the lag function

    proc sort data=your_dataset;
     by descending id;
    run;
    
    data your_dataset;
     set your_dataset;
     next_row_salary = lag(salary);
    run;
    
    proc sort; by id; run;
    

    Options 2: Use proc expand

    proc expand data=your_dataset method=none;
     by id;
     convert salary = next_row_salary / transformout=(lead 1);
    run;
    

提交回复
热议问题