各位大神,有个问题困惑我很久,实在不能解决,还烦请各位帮助。
我现在有一系列数字类似于1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 5 6 7
data check;
input num @@;
numlag=lag(num);
retain policyyear;
if missing(numlag) then policyyear=2013;
else if numlag<num then policyyear=lag(policyyear);
else if numlag>num then policyyear=lag(policyyear)+1;
datalines;
1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 5 6 7
;run;
我希望可以对于前1,2,3,4,5,6 都添加一个变量year为2013;
从第二个1开始,变量year为2014;
第三个1开始,变量year为2015;
我这边是举个例子,实际的数量每年都是不一致的;
我尝试使用lag函数来处理这个问题单但介于天杀lag函数先天性的在条件语句中的不和谐,一直不能成功;
还请各位大神给点建议,非常感谢。