如何使用sas筛选时间段并且求和?
数据格式siteyearmonthvalue51701,1951,1,10,51701,1951,2,20,51701,1951,3,30,51701,1951,4,40...
数据格式
site year month value
51701,1951,1,10,
51701,1951,2,20,
51701,1951,3,30,
51701,1951,4,40,
51701,1951,5,50,
51701,1951,6,60,
51701,1951,7,70,
51701,1951,8,80,
51701,1951,9,90,
51701,1951,10,10,
51701,1951,11,20,
51701,1951,12,30,
51701,1952,1,10,
51701,1952,2,20,
51701,1952,3,30,
51701,1952,4,40,
51701,1952,5,50,
51701,1952,6,60,
.............................
我想要把第一年九月份以后的数据到第二年3月的数据筛出来,怎么筛选啊?谢谢各位大神 展开
site year month value
51701,1951,1,10,
51701,1951,2,20,
51701,1951,3,30,
51701,1951,4,40,
51701,1951,5,50,
51701,1951,6,60,
51701,1951,7,70,
51701,1951,8,80,
51701,1951,9,90,
51701,1951,10,10,
51701,1951,11,20,
51701,1951,12,30,
51701,1952,1,10,
51701,1952,2,20,
51701,1952,3,30,
51701,1952,4,40,
51701,1952,5,50,
51701,1952,6,60,
.............................
我想要把第一年九月份以后的数据到第二年3月的数据筛出来,怎么筛选啊?谢谢各位大神 展开
展开全部
data test;
infile cards dlm=',';
input site $ year month value;
cards;
51701,1951,1,10,
51701,1951,2,20,
51701,1951,3,30,
51701,1951,4,40,
51701,1951,5,50,
51701,1951,6,60,
51701,1951,7,70,
51701,1951,8,80,
51701,1951,9,90,
51701,1951,10,10,
51701,1951,11,20,
51701,1951,12,30,
51701,1952,1,10,
51701,1952,2,20,
51701,1952,3,30,
51701,1952,4,40,
51701,1952,5,50,
51701,1952,6,60,
51701,1952,7,70,
51701,1952,8,80,
51701,1952,9,90,
51701,1952,10,10,
51701,1952,11,20,
51701,1952,12,30,
51701,1953,1,10,
51701,1953,2,20,
51701,1953,3,30,
51701,1953,4,40,
51701,1953,5,50,
51701,1953,6,60,
51701,1953,7,70,
51701,1953,8,80,
51701,1953,9,90,
51701,1953,10,10,
51701,1953,11,20,
51701,1953,12,30
;
run;
*第一年9月份以后到第二年3月份的数据,我理解是51年10月-52年3月,52年10月-53年3月...
*时间段位6个月,要求它们value的和,可以先求和再筛选。
*我的方法是利用lag函数,进行倒推,依次是value,lag(value),....,然后求和
*最后进行月份筛选需要的和,这里是从每年3月倒推至上一年的10月
;
data need ;
set test;
val_sum = value + lag(value)+ lag2(value)
+ lag3(value) + lag4(value) + lag5(value);
if month = 3 then output;
run;
infile cards dlm=',';
input site $ year month value;
cards;
51701,1951,1,10,
51701,1951,2,20,
51701,1951,3,30,
51701,1951,4,40,
51701,1951,5,50,
51701,1951,6,60,
51701,1951,7,70,
51701,1951,8,80,
51701,1951,9,90,
51701,1951,10,10,
51701,1951,11,20,
51701,1951,12,30,
51701,1952,1,10,
51701,1952,2,20,
51701,1952,3,30,
51701,1952,4,40,
51701,1952,5,50,
51701,1952,6,60,
51701,1952,7,70,
51701,1952,8,80,
51701,1952,9,90,
51701,1952,10,10,
51701,1952,11,20,
51701,1952,12,30,
51701,1953,1,10,
51701,1953,2,20,
51701,1953,3,30,
51701,1953,4,40,
51701,1953,5,50,
51701,1953,6,60,
51701,1953,7,70,
51701,1953,8,80,
51701,1953,9,90,
51701,1953,10,10,
51701,1953,11,20,
51701,1953,12,30
;
run;
*第一年9月份以后到第二年3月份的数据,我理解是51年10月-52年3月,52年10月-53年3月...
*时间段位6个月,要求它们value的和,可以先求和再筛选。
*我的方法是利用lag函数,进行倒推,依次是value,lag(value),....,然后求和
*最后进行月份筛选需要的和,这里是从每年3月倒推至上一年的10月
;
data need ;
set test;
val_sum = value + lag(value)+ lag2(value)
+ lag3(value) + lag4(value) + lag5(value);
if month = 3 then output;
run;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询