问题描述
我有一个名为输入"的数据集,其中包含以下观察结果
I've a dataset called 'input' with the following observations
身份证工资
10 1000
20 2000
30 3000
40 4000
ID Salary
10 1000
20 2000
30 3000
40 4000
我需要一个具有以下观察结果的输出数据集
I need an output dataset with following observations
ID 工资 Next_row_Salary
10 1000 2000
20 2000 3000
30 3000 4000
40 4000 空
ID Salary Next_row_Salary
10 1000 2000
20 2000 3000
30 3000 4000
40 4000 null
注意:场景是下一个观察的薪水应该是列Next_Row_salary的当前观察值.如果没有下一个观察值,则列 Next_Row_salary 的当前观察值应为空".
Note: The scenario is next obersavtion's salary should be the current observation's value for the column Next_Row_salary.If there is no next observation then the current observation's value for the column Next_Row_salary should be 'null'.
请帮助我为这个场景创建一个 sas 代码.
Kindly help me out in creating a sas code for this scenario.
推荐答案
有几种方法可以实现这一点,以下是我的方法.
There are a few ways to achieve this, here's how I would do it.
data have;
input ID Salary;
cards;
10 1000
20 2000
30 3000
40 4000
;
run;
data want;
recno=_n_+1;
set have end=last;
if not last
then set have (keep=salary rename=(salary=next_row_salary)) point=recno;
else call missing(next_row_salary);
run;
这篇关于在当前观察中读取下一个观察值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!