sas:将数组转化为矩阵

/*数组表*/
data a;
input name $ other $; 
cards;
a b
a c
a d
b a
b d
b f
c b 
c d
c a
c e
d c
d a
d e 
d f
e b 
e d
f a
f c
f b
a f
;
    /*排序*/
proc sort data=a out=c;
by name other;
run;
    /*复制表*/
data b;
input name2 $ other2 $;
cards;
a b
a c
a d
b a
b d
b f
c b 
c d
c a
c e
d c
d a
d e 
d f
e b 
e d
f a
f c
f b
a f
;
    /*排序*/
proc sort data=b out=d;
by name2 other2;
run;
    /*选择双向相关的数组*/
proc SQL;
create table cccc as select distinct a.name,a.other
from a,b
where a.other=b.name2 and a.name=b.other2;
run;
data m;
set cccc;
d=1;
run;
    /*利用转置过程*/
proc transpose data=m out=n(rename=(_name_=other));
var d;
by name;
id other;
label other=;
run;
proc contents data=n out=p;run;
proc sql;
select name into:var separated by ','  from p where name not like 'name' ;
create table x as select name,&var from n;
quit;
data u;
set x;
drop other;
run;

还有一个在知乎上问过的相关问题:
https://www.zhihu.com/question/46338489?from=profile_question_card
两个问题相互补充,很适合做社会网络分析

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值