简体   繁体   English

如何在sas中对连续整数进行分组?

[英]How do I group consecutive integers in sas?

I would like to group consecutive integers in sas. 我想在sas中对连续整数进行分组。

data h;
input integer temperature;
cards;
1 33
2 33
3 34
5 35
6 37
9 33
10 34
;
run;

I would like my output to look like this 我希望我的输出看起来像这样

1 33 1
2 33 1
3 34 1
5 35 2
6 37 2
9 33 3
10 34 3

Thanks for your help, in advance. 预先感谢您的帮助。

Look at the DIF and retain function. 查看DIF并保留功能。 Note that your criteria and example don't match. 请注意,您的条件和示例不匹配。 You say consecutive but seem to imply increase of 0 OR 1. 您说连续的,但似乎意味着增加0或1。

DIF calculates the difference between current and previous observation. DIF计算当前观测值与先前观测值之间的差异。 RETAIN holds a value across rows until it's explicitly changed. RETAIN跨行保存一个值,直到明确更改为止。

Data want;
Set have;
 Retain group 0;
 Temp_dif = dif(temp);
 If temp_dif > 1 then group + 1;
 Run;

EDIT: 编辑:

Data want;
Set have;
 Retain group 0;
 INT_dif = dif(integer);
 If int_dif > 1 then group + 1;
 Run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM