有如下数据集:
data a;
if _n_<8 then g=1;else g=2;
input x $ @@;
y=dif(x);
cards;
07 12 13 14 15 19 22 23 24 29 30 31 32 36
;run;
想得到如下效果:g=1 result='07,12-15,19,22' ; g=2 result='23-24,29-32,36'
意思就是按照g来分组,将x进行汇总,得到的字符串如有连号,用‘-’连接。
问题貌似不难,但是想了一个晚上,很受打击。。。
貌似按照y=dif(x)可以算,但是感觉写出来会很啰嗦,不知有没有更简洁的办法,我记得前段时间貌似坛子里看到过。。
One way as follow:
data b;set a;
retain z 0;
if y^=1 then z+1;
run;
..... Still have a loooooong way to go .....