楼主: hqs811
3797 25

请教各位如何实现一个程序,比较复杂 [推广有奖]

21
jingju11 发表于 2014-8-20 11:30:07 |只看作者 |坛友微信交流群
加上“同时”或许可能增加程序的难度。可是实际意义什么呢?
at_least_1_authors_repeat = 0 说明此文章的作者从未写过别的文章。
at_least_2_authors_repeat = 0 说明该文章的作者们除此文章之外从未有过任何的两两合作。
。。。。
其中的逻辑或许是找出其他题目中的作者和该题目作者的最大相似程度。
京剧
  1. data test;
  2.   length Title $20. Authors $200.;
  3.   input Title Authors & Number_authors ;
  4.   cards;
  5. Title1   Name A|Name B   2
  6. Title2   Name B|Name C   2
  7. Title3   Name C|Name D|Name B   3
  8. Title4   Name D|Name E   2
  9. Title5   Name B|Name C|Name D   3
  10. Title6   Name F|Name G|Name H|Name I|Name J|Name K   6
  11. Title7   Name A|Name B|Name C|Name D|Name E|Name F   6
  12. Title8   Name A|Name B|Name C|Name D|Name E|Name F   6
  13. Title9   Name U   1
  14. ;

  15. data test2;
  16.         set test;
  17.         array t[200] $64. _temporary_;
  18.         call missing(of t[*]);
  19.         do i =1 to Number_authors;
  20.                 t[i] =scan(authors, i, '|');
  21.         end;
  22.         k =0;
  23.         do i =1 to nobs;
  24.                 set test(keep=authors rename=(authors=authors1)) point=i nobs=nobs;
  25.                 if _n_ ^=i then do j =1 to Number_authors;
  26.                         if not missing(t[j]) then if find(authors1, cats(t[j])) then s ++1;
  27.                 end;
  28.                 k =max(k, s);
  29.                 s =0;
  30.         end;
  31.         array f[5]         at_least_1_authors_repeat at_least_2_authors_repeat at_least_3_authors_repeat
  32.                                                         at_least_4_authors_repeat at_least_5_authors_repeat;
  33.         do i =1 to dim(f);
  34.                 f[i] =0;
  35.                 if i <=k then f[i] =1;
  36.         end;
  37.         drop k j s authors1;
  38. run;
复制代码

使用道具

22
pobel 在职认证  发表于 2014-8-20 11:35:01 |只看作者 |坛友微信交流群
hqs811 发表于 2014-8-20 11:21
多谢您详实的回复!!

代码信息量比较大,我研究先研究一下哈,
format BINARYw.的最大长度应该是64

使用道具

23
hqs811 发表于 2014-8-20 11:36:01 |只看作者 |坛友微信交流群
jingju11 发表于 2014-8-20 11:30
加上“同时”或许可能增加程序的难度。可是实际意义什么呢?
at_least_1_authors_repeat = 0 说明此文章的 ...
谢谢回复  

你说的有一定道理,但是at_least_2_authors_repeat,如果每个observation都赋予了这个变量,那么通过这个变量的distribution和frequency可以研究   两人小组(甚至N人)的这种合作形式  在数据中所占的比例 以及他们对应的数据由哪些性质 ETC...

使用道具

24
hqs811 发表于 2014-8-20 11:39:34 |只看作者 |坛友微信交流群
pobel 发表于 2014-8-20 11:35
format BINARYw.的最大长度应该是64
哦,这样,那我研究一下看有什么其他的办法吧。
您的程序已经帮了很大的忙了,谢谢!

使用道具

25
ziyenano 发表于 2014-8-20 13:59:40 |只看作者 |坛友微信交流群
data test;
  input Title &   $10.        Authors $60.              Number_authors ;
  authors=upcase(authors);
  cards;
Title 1    Name A | Name B                                                                                     2
Title 2    Name A | Name B  | Name C                                                                    3
Title 3    Name A | Name F  | Name B | Name Z                                                     4
Title 4    NAME A                                                                                                   1
Title 5    NAME F | NAME T                                                                                    2
Title 6    NAME F | NAME Z  | Name A | Name N | Name B | Name X                       6   
;



/*展开所有作者*/
data ex;
length author $10;
set test;
do i=1 to Number_authors;
   author=strip(scan(authors,i,'|'));
output;
end;
keep Title author;
run;


proc sql;
/*计算每个title的作者在其他组出现的情况*/
create table ex1 as
select t.title,t.author,
t1.title as title1
from ex t
left join
ex t1
on t.author=t1.author
and t.title ^=t1.title
order by t.title,t.author,t1.title;

/*计算每个title的作者在其他组同时出现的作者个数 对应变量cnt*/
create table ex2 as
select t.title,t.title1,sum(case when t.title1 is null then 0 else 1 end) as cnt
from ex1 t group by t.title,t.title1
order by t.title,t.title1 ;

/*汇总,取每个title的cnt最大值,并根据max(cnt)赋值at_least_x_authors_repeat*/
create table ex3 as
select title,
max(cnt) as max_cnt,
case when max(cnt)>=1 then 1 else 0 end as at_least_1_authors_repeat,
case when max(cnt)>=2 then 1 else 0 end as at_least_2_authors_repeat,
case when max(cnt)>=3 then 1 else 0 end as at_least_3_authors_repeat,
case when max(cnt)>=4 then 1 else 0 end as at_least_4_authors_repeat,
case when max(cnt)>=5 then 1 else 0 end as at_least_5_authors_repeat
from ex2
group by title;

已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
hqs811 + 5 + 1 + 1 + 1 思路清晰,厉害
pobel + 5 + 5 + 5 + 5 精彩帖子

总评分: 论坛币 + 10  学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

使用道具

ziyenano 发表于 2014-8-20 13:59
data test;
  input Title &   $10.        Authors $60.              Number_authors ;
  authors=upca ...

使用道具

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

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

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

GMT+8, 2024-4-25 11:41