Arrays 按组修改SAS中的最终列值
我有以下数据集:Arrays 按组修改SAS中的最终列值,arrays,loops,sas,Arrays,Loops,Sas,我有以下数据集: Student TestDayStart TestDayEnd 001 1 5 001 6 10 001 11 15 002 1 4 002 5 9 00
Student TestDayStart TestDayEnd
001 1 5
001 6 10
001 11 15
002 1 4
002 5 9
002 10 14
我想将最后一个“TestDayEnd”作为每个学生的“TestDayStart”的最终值。
因此,数据应该如下所示:
Student TestDayStart TestDayEnd
001 1 5
001 6 10
001 11 15
001 15 15
002 1 4
002 5 9
002 10 14
002 14 14
我不太确定如何在SAS中做到这一点。如有任何见解,将不胜感激 对数据集进行排序后,可以在数据步骤中执行此操作
proc sort data=have;
by student testdaystart testdayend;
run;
现在,您可以在数据步骤中使用by
和retain
语句。by
语句允许您查找最后一个学生,而retain
语句允许您在数据集中保留上一个值
data want;
set have;
retain last_testdayend;
by student testdaystart testdayend;
output;
last_testdayend = testdayend;
if last.student then do;
if testdaystart ne testdayend then do;
testdaystart = last_testdayend;
testdayend = last_testdayend;
output; * this second output statement creates a new record in the dataset;
end;
end;
drop last_testdayend;
run;