sas:将数组转化为矩阵

来源:互联网 发布:网络金融理财咨询 编辑:程序博客网 时间:2024/06/12 01:28
/*数组表*/data a;input name $ other $; cards;a ba ca db ab db fc b c dc ac ed cd ad e d fe b e df af cf ba f;    /*排序*/proc sort data=a out=c;by name other;run;    /*复制表*/data b;input name2 $ other2 $;cards;a ba ca db ab db fc b c dc ac ed cd ad e d fe b e df af cf ba f;    /*排序*/proc sort data=b out=d;by name2 other2;run;    /*选择双向相关的数组*/proc SQL;create table cccc as select distinct a.name,a.otherfrom a,bwhere 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
两个问题相互补充,很适合做社会网络分析

2 0
原创粉丝点击