楼主: jpingl1273
3790 20

[原创博文] 求sas程序 [推广有奖]

11
jpingl1273 发表于 2011-4-13 08:51:46
对  ,比如有这样的一个数据
70
80
30
160
110
200
168
30
963
45
185
972
9
15
42
123
34
44
55
88
99
这样的话符合要求就只有三组,共计11个数字,第一组是70 80 30 第二组是9 15 42 第三组是34 44 55 88 99 8# myc_sas

12
SYJ19881128 发表于 2011-4-13 14:37:10
,,,,,,,,,,,

13
myc_sas 发表于 2011-4-13 18:15:38
11# jpingl1273

嗯,昨天最后时间紧,没仔细检查,忘记加最后的那个判断了。

data test2(drop=i);
    set test end=last;
    if i<100 then do;
        j+
1;
    end;
    else do;
        if j>1 then do;
            output;
        end;
        j=
0;
    end;
    if last and j>1 then do;
        output;
    end;
run;

14
jpingl1273 发表于 2011-4-13 20:35:59
结果还是一样!!!
和前面的程序的结果一样!!!呵呵    13# myc_sas

15
myc_sas 发表于 2011-4-14 17:35:39
jpingl1273 发表于 2011-4-13 20:35
结果还是一样!!!
和前面的程序的结果一样!!!呵呵    13# myc_sas
不会啊,我这里运行出来应该就是你要的结果,一共三组,个数分别是3,3,5

完整的代码:

data test;
    infile datalines;
    input i;
    datalines;
70
80
30
160
110
200
168
30
963
45
185
972
9
15
42
123
34
44
55
88
99
;
run;

data test2(drop=i);
    set test end=last;
    if i<100 then do;
        j+
1;
    end;
    else do;
        if j>1 then do;
            output;
        end;
        j=
0;
    end;
    if last and j>1 then do;
        output;
    end;
run;
已有 1 人评分热心指数 收起 理由
jpingl1273 + 1 好人 谢谢你

总评分: 热心指数 + 1   查看全部评分

16
jpingl1273 发表于 2011-4-14 19:15:14
呵呵  忘了给你说了   对着呢  谢谢你哈  好人一生平安!谨祝 15# myc_sas

17
shenliang_111 发表于 2011-8-23 13:53:50
try this:
data test;
    infile datalines;
    input i;
    datalines;
70
80
30
160
110
200
390
67
88
23
78
23
789
23
232
32
2323
123
23
22
2322
22
222
22
22
33
33
33
33
168
30
963
45
185
972
9
15
42
;
run;
data new;
set test;
k=(i lt 100);
run;
data result3(keep=i counter summ);
set new;
by k notsorted;
if first.k then cnt=0;
cnt+1;
if last.k then do;
   if not(cnt ge 2 and k=1) then delete;
      else do;
               counter+1;
                     do j=_n_-cnt+1 to _n_;
                            set new(keep=i) point=j;
                                summ=sum(summ,i);
                                output;
                         end;
                        end;
end;
run;

18
zhangzachary 发表于 2011-8-23 16:52:26
  1. data a;
  2. input x;
  3. cards;
  4. 73.499878
  5. 87.406372
  6. 38.898289
  7. 163.500153
  8. 100.398247
  9. 207.5
  10. 168.703308
  11. 29.898287
  12. 963.000122
  13. 45.898289
  14. 185.601715
  15. 972.999878
  16. 9.8984
  17. 15.203313
  18. 42.695187
  19. 834.999939
  20. 216.500061
  21. 444.703247
  22. 20.601563
  23. 79.093628
  24. 273
  25. 273.000061
  26. 396.906311
  27. 406.296722
  28. 49.796963
  29. 75.601501
  30. ;
  31. run;


  32. data c;
  33. set a;
  34. if x<100 and y<1 then y+1;
  35. if x>=100 then y=0;
  36. run;


  37. proc summary data=c;
  38. var x;
  39. by y notsorted;
  40. output out=d(where=(y=1) drop=_type_ _freq_) sum=sum n=n;
  41. run;
复制代码
寒冰凤凰 My blog: http://blog.sina.com.cn/u/1058955485

19
jpingl1273 发表于 2011-8-23 19:39:48
shenliang_111 发表于 2011-8-23 13:53
try this:
data test;
    infile datalines;
xiexie ha     heheh

20
jpingl1273 发表于 2011-8-23 19:40:03
zhangzachary 发表于 2011-8-23 16:52
xiexie ha     heheh

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-2 22:24