SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

楼主: shiyiming
打印 上一主题 下一主题

sas一个取最大值的问题[求助,急!!!]

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
11#
 楼主| 发表于 2010-8-25 20:00:01 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

不大行呃。。。结果有问题,然后也看不大懂程序所以也不知道怎么调。。。
其实上次的那个程序真的只差最后的一步随机选并列的情况了。。。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
12#
 楼主| 发表于 2010-8-25 20:19:47 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

啥问题? 排错了还是不随机?
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
13#
 楼主| 发表于 2010-8-25 21:12:24 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

排错。。。我还在想办法找问题,但是水平实在有限@@
搞不大清为什么这个版本和前面那个差别这么大。。。

509  data temp(drop=i);
510      do _n_=1 by 1 until(last.company);
511          set temp;
512          by company;
513          array industry_count_ {*} _numeric_;
514          array temp {10} _temporary_;
515          do i=1 to dim(industry_count_);
516              industry_count_(i)=sum(ifn(missing(industry_count_(i)),0,industry_count_(i)),temp(i))
516! ;
517              temp(i)=industry_count_(i);
518          end;
519          output;
520      end;
521  run;

ERROR: Array subscript out of range at line 516 column 90.

会不会因为我手上这个表太大了不能用array?将近30w行的数据。。。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
14#
 楼主| 发表于 2010-8-25 21:15:19 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

然后industry_name_1全部显示是year,industry_count_1全部等于year的值。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
15#
 楼主| 发表于 2010-8-25 22:45:43 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

把year改成字符变量估计就对了
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
16#
 楼主| 发表于 2010-8-26 01:54:04 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

嗯!的确~大谢前辈!
不过还有最后一个小问题,industry_count的计数器一直在加(没有按照公司分开在换公司的时候计数器没有清零)导致最后一直加到了6000多。
应该怎么改一下原来的代码?
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
17#
 楼主| 发表于 2010-8-26 05:50:31 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

我跟版主是一个师傅教出来的。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
18#
 楼主| 发表于 2010-8-26 07:22:24 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

多谢老猪,慢慢看 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
19#
 楼主| 发表于 2010-8-26 20:14:09 | 只看该作者

Re: sas一个取最大值的问题[求助,急!!!]

大谢这位前辈!
这段程序连我这种水平都看懂了,感动:)
主要问题都大致解决了~
受教了。

[quote=&quot;死猪头&quot;:iphbomve]我跟版主是一个师傅教出来的。
[code:iphbomve]
data raw;
    length COMPANY $1 YEAR $4 INDUSTRY $40;
    input;
    COMPANY=scan(_infile_,1,' ');
    YEAR=scan(_infile_,2,' ');
    INDUSTRY=substr(_infile_,8,anydigit(_infile_,8)-9);
    COUNT=input(scan(_infile_,-1,' '),best&#46;);
datalines;
A 1999 Communications and Media 1
A 1999 Computer Software and Services 1
A 1999 Internet Specific 5
A 2000 Communications and Media 1
A 2000 Computer Software and Services 7
A 2000 Internet Specific 1
A 2001 Communications and Media 1
A 2001 Computer Software and Services 1
A 2001 Internet Specific 1
B 1999 Biotechnology 8
B 1999 Communications and Media 7
B 1999 Computer Hardware 2
B 1999 Computer Software and Services 23
B 1999 Consumer Related 23
B 1999 Industrial/Energy 12
B 1999 Internet Specific 21
B 1999 Medical/Health 7
B 1999 Other Products 34
B 1999 Semiconductors/Other Elect&#46; 5
B 2000 Biotechnology 13
B 2000 Communications and Media 14
B 2000 Computer Hardware 5
B 2000 Computer Software and Services 34
B 2000 Consumer Related 12
B 2000 Industrial/Energy 19
B 2000 Internet Specific 56
B 2000 Medical/Health 11
B 2000 Other Products 25
B 2000 Semiconductors/Other Elect&#46; 3
;

proc sort data=raw out=zhutou;
        by company industry year;
run;
data sizhutou(drop=count);
        do until (last&#46;industry);
                do until(last&#46;year);
                        set zhutou;
                        by company industry year;
                        acum_count = sum(acum_count, count);
                end;
                random_number = ranuni(12345);
                output;
        end;
run;
proc sort data=sizhutou out=zhupo;
        by company year descending acum_count random_number;
run;
data zhuzai;
        do _n_=1 by 1 until(last&#46;year);
                set zhupo;
                by company year;
                if _n_ &lt; 3 then output;
        end;
run;
[/code:iphbomve][/quote:iphbomve]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
20#
 楼主| 发表于 2010-8-27 01:46:57 | 只看该作者

一个新的小问题

噢,BTW,这个程序有个前提是每个公司的这些年份都是连着的(你看我给是1999-2001和1999-2000),如果中间跳开(实际情况是数据从1958-2010间断断续续有)那个acum_count就会有问题:

只有有投资发生的年份里这个行业才有这个值,但是事实上比如1999年公司在这个行业A里投了100次,次年没投到时在另一个行业B里投了1次,结果这个程序走出来的结果2000年前最多的行业就变成了B哪怕只有一次)。

我之前用过一个很复杂的办法把所有每个行业在没有投资事件发生的年份(从数据起止年间)里面都做了0,但是程序写得很纠结很低效(10个industry还好,如果再多点这个数据冗余就非常严重了),前辈们有没有好点的办法实现?

比如数据变成:
A 1989 Communications and Media 1
A 1997 Computer Software and Services 1
A 1999 Internet Specific 5
A 2000 Communications and Media 1
A 2000 Computer Software and Services 7
A 2000 Internet Specific 1
A 2001 Communications and Media 1
A 2001 Computer Software and Services 1
A 2008 Internet Specific 1
B 1994 Biotechnology 8
B 1999 Communications and Media 7
B 1999 Computer Hardware 2
B 1999 Computer Software and Services 23
B 1999 Consumer Related 23
B 1999 Industrial/Energy 12
B 1999 Internet Specific 21
B 1999 Medical/Health 7
B 1999 Other Products 34
B 1999 Semiconductors/Other Elect. 5
B 2000 Biotechnology 13
B 2000 Communications and Media 14
B 2000 Computer Hardware 5
B 2000 Computer Software and Services 34
B 2000 Consumer Related 12
B 2000 Industrial/Energy 19
B 2000 Internet Specific 56
B 2000 Medical/Health 11
B 2008 Other Products 25
B 2008 Semiconductors/Other Elect. 3
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-4 01:37 , Processed in 0.079229 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表