检查sas中的连续状况

时间:2016-10-03 08:17:13

标签: sas

 DATA have;
    input month 1-2 name $ 5-9 spending $ 12-13 ;
    cards;
1   Simon  2
2   Simon  2
3   Simon  3
4   Simon  5
5   Simon  0
6   Simon  1
7   Simon  0
8   Simon  0
9   Simon  0
10  Simon  0
11  Simon  0
12  Simon  0
1   John   3
2   John   3
3   John   3
4   John   5
5   John   0
6   John   0
7   John   0
8   John   0
9   John   0
10  John   0
11  John   1
12  John   0
;
RUN;

如何连续6次检查" 0" ? 如果支出超过5并且下一次连续6支出是" 0"然后我需要在第6个月末将其标记为0。 我应该使用retain还是数组,请帮忙吗? 下面是我想要新列的方式..

 DATA want;
    input month 1-2 name $ 5-9 spending  12-13 tag 14-15;
    cards;
1   Simon  2 0
2   Simon  2 0
3   Simon  4 0
4   Simon  5 1
5   Simon  0 1
6   Simon  1 1
7   Simon  0 1
8   Simon  0 1
9   Simon  0 1
10  Simon  0 1
11  Simon  0 1
12  Simon  0 0
1   John   3 0
2   John   3 0
3   John   3 0
4   John   5 1
5   John   0 1
6   John   0 1
7   John   0 1
8   John   0 1
9   John   0 1
10  John   0 0
11  John   1 0
12  John   0 0
;
RUN;

0 个答案:

没有答案