楼主: jpingl1273
3383 10

求sas整理数据程序! [推广有奖]

  • 1关注
  • 2粉丝

副教授

77%

还不是VIP/贵宾

-

威望
0
论坛币
3017 个
通用积分
12.0707
学术水平
6 点
热心指数
12 点
信用等级
7 点
经验
1454 点
帖子
639
精华
0
在线时间
1294 小时
注册时间
2008-9-5
最后登录
2024-3-7

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
要求如题,比如有一列数据:

122.101715

777

67.296753

514.296936

11.906313

669.19519

16.6015

1471.5

19.2969

48.406376

744.898438

58.398251

64.601601

265.000153

84.296753

606.203125

461.898438

566.601563

34.796963

790.398438

54.5

56.406311

386.499939

887.5

45

1638.000122

468

28.093687

606.703003

69.203316

97.59375

73.499878

87.406372

38.898289

要求筛选出小于100的数据,且如果小于100的数据有两个以上是连续在一起的话,视作一组,(意思就是小于100的数据连在一起的有2个以上的作为一组,组的分界线就是它上下的大于100的数据,这样的作为一组),做出来的目的就是想求出总的组数,和各组间数据的总数(计数)!谢谢各位大侠   
求sas计算程序!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:整理数据 sas计算程序 各位大侠 计算程序 在一起 数据 程序 SAS

回帖推荐

sas_user 发表于2楼  查看完整内容

1# jpingl1273 data l; input x@@; if x=100 then count=.; datalines; 73.499878 87.406372 38.898289 163.500153 100.398247 207.5 168.703308 29.898287 963.000122 45.898289 185.601715 972.999878 9.8984 15.203313 42.695187 834.999939 216.500061 444.703247 20.601563 79.093628 273 273.000061 396.906311 406.296722 49.796963 75.601501 ; run;   ...

本帖被以下文库推荐

沙发
sas_user 发表于 2011-4-19 12:16:38 |只看作者 |坛友微信交流群
1# jpingl1273

data l;
input x@@;
if x<100 then count=1;
else; if x>=100 then count=.;
datalines;
73.499878
87.406372
38.898289
163.500153
100.398247
207.5
168.703308
29.898287
963.000122
45.898289
185.601715
972.999878
9.8984
15.203313
42.695187
834.999939
216.500061
444.703247
20.601563
79.093628
273
273.000061
396.906311
406.296722
49.796963
75.601501
;
run;
 
data need (keep=subtotal);
set l;
by count notsorted;
if first.count then do;
               subtotal=
0;
               group=
0; end;
           group+
1;
           subtotal+x;
if first.count and last.count then delete;
if last.count and count ne .;
run;
已有 2 人评分经验 论坛币 热心指数 收起 理由
bakoll + 3 + 3 精彩帖子
crackman + 1 鼓励积极发帖讨论

总评分: 经验 + 3  论坛币 + 3  热心指数 + 1   查看全部评分

使用道具

藤椅
jpingl1273 发表于 2011-4-19 21:34:07 |只看作者 |坛友微信交流群
呵呵 谢谢你的回复
我最终要的是符合条件的组数以及这些组一共有多少个数据(要的是个数),最总其实要的是总的个数除以组数 2# sas_user

使用道具

板凳
sas_user 发表于 2011-4-20 02:17:39 |只看作者 |坛友微信交流群
3# jpingl1273
以下是改过的,再试一下?如果不对,我再改。

 
data need ;
set l end=end;
by count notsorted;
if first.count then do; subtotal=0; group+1; end;
subtotal+x;
if first.count and last.count then delete;
if count = . then delete;
drop count;
run;


proc sql;
select count(x)/(count (distinct group)) as result from need;
quit;

使用道具

报纸
zhaoping603 发表于 2011-4-20 10:23:05 |只看作者 |坛友微信交流群
data l;
input x@@;
datalines;
73.499878
87.406372
38.898289
163.500153
100.398247
207.5
168.703308
29.898287
963.000122
45.898289
185.601715
972.999878
9.8984
15.203313
42.695187
834.999939
216.500061
444.703247
20.601563
79.093628
273
273.000061
396.906311
406.296722
49.796963
75.601501
;
run;
data n;
set l;
if x<100 then count=1;
else  count=.;
if  count then temp+count;
else temp=0;
if  temp>=3 then do;
     total_group+1;
  total_num+temp;
end;

proc sql;
create table numb as
select max(total_group) as t_group,
        max(total_num)   as t_num,
        max(total_num)/max(total_group) as ratio
  from  n;
已有 1 人评分热心指数 收起 理由
crackman + 1 鼓励积极发帖讨论

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

使用道具

地板
sas_user 发表于 2011-4-20 11:26:51 |只看作者 |坛友微信交流群
3# jpingl1273

"最总其实要的是总的个数除以组数"
总的个数是不是指小于100的连在一起的数字的个数?组数是不是指小于100的连在一起的数字共有多少组?请楼主确认是不是我理解错了?总个数除以组数是不是10/4呢?

使用道具

7
hopewell 发表于 2011-4-20 19:28:32 |只看作者 |坛友微信交流群
  1. data temp(keep=n);
  2.     retain flag 0 n -1;
  3.     do until(eof);
  4.         set raw end=eof;
  5.         if flag & (var lt 100) then do;
  6.             if n ge 1 then output;
  7.             n=-1;
  8.         end;
  9.         else do;
  10.             flag=(var lt 100);
  11.             n+1;
  12.         end;
  13.     end;
  14. run;
复制代码
已有 1 人评分热心指数 收起 理由
crackman + 1 鼓励积极发帖讨论

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

观钓颇逾垂钓趣 种花何问看花谁

使用道具

8
sas_user 发表于 2011-4-20 20:20:14 |只看作者 |坛友微信交流群
7# hopewell
hopewell能不能给讲讲flag跟var lt 100的关系呀?很牛的程序,就是看不大明白。多谢了。

使用道具

9
zhaoping603 发表于 2011-4-22 13:51:50 |只看作者 |坛友微信交流群
7# hopewell
同问,本人新手,也没看明白。希望解释一下,多谢了。

使用道具

10
sunnyxidian 发表于 2011-4-22 17:24:23 |只看作者 |坛友微信交流群
看这个行吗
data temp(keep=n);
   retain n 0;
   set raw;
        if var<100 then  n+1;
        else  if n>1 then
                         do;
                               output;
                               n=0;
                          end;
                else   n=0;
run;
proc sql;
    select count(*) as c, sum(n) as s, sum(n)/count(*) as r from temp;
quit;

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-8 12:16