(假设您的数据按主题和日期排序)数据合并1;合并有有(重命名=(天=第二天的主题=下一个主题)下降=测量firstobs = 2);如果subject = nextsubject,则_day = day to nextday-1;输出 ;结尾 ;否则做;_day =天;输出 ;结尾 ;第二天下一天的下课日;重命名_day =天;跑步 ;I have a data set containing a measurement and the specific day it was collected. I would like to replicate the values between days, up until the last measurement day. For example, here is the data before it is replicated: Measurement DaySubject1 .85 -1Subject1 .86 1 Subject1 .91 7 Subject1 .83 9 Subject2 .77 0 Subject2 .82 5 Subject2 .86 12 I would like to modify the data set above to look like the following: Measurement DaySubject1 .85 -1Subject1 .85 0Subject1 .86 1Subject1 .86 2Subject1 .86 3Subject1 .86 4Subject1 .86 5 Subject1 .86 6 Subject1 .91 7Subject1 .91 8 Subject1 .83 9 Subject2 .77 0Subject2 .77 1Subject2 .77 2Subject2 .77 3Subject2 .77 4 Subject2 .82 5 Subject2 .82 6Subject2 .82 7 Subject2 .82 8 Subject2 .82 9 Subject2 .82 10Subject2 .82 11 Subject2 .86 12 解决方案 You can do a 'look ahead merge' by offsetting the merged data by one row, and omitting the by statement;(assumes your data is sorted by Subject and Day)data merge1 ; merge have have (rename=(day=nextday subject=nextsubject) drop=measurement firstobs=2) ; if subject = nextsubject then do _day = day to nextday - 1 ; output ; end ; else do ; _day = day ; output ; end ; drop day nextday nextsubject ; rename _day = day ;run ; 这篇关于按组复制SAS中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 05:52