SAS邻接矩阵创建

时间:2016-12-21 19:07:22

标签: sas social-networking adjacency-list adjacency-matrix sna

我创建了这个表: Table

由此我想创建一个邻接矩阵,显示表共享employee_id的数量。它看起来像这样(我认为): enter image description here 我不确定我是否正确地采用这种方式。我想我可能做错了。我知道如果我有更多的SAS产品,这可能会更容易,但我只有基本的SAS企业指南。

我真的很感激帮助。谢谢。

3 个答案:

答案 0 :(得分:1)

我认为这就是你想要的,但它没有给出你所展示的答案。

data id;
   input id:$4. human alien wizard;
   cards;
1005 1 1 0
1018 0 0 1
1022 0 0 1
1024 1 0 0
1034 0 1 0
1069 0 1 0
1078 1 0 0
1247 1 1 1
;;;;
   run;

proc corr noprint nocorr sscp out=sscp;
   var human alien wizard;
   run;
proc print;
   run;

enter image description here

答案 1 :(得分:1)

这里使用PROC CORR的另一种方式仍然比上面的解决方案更好。而且您不需要过滤 - 它与变量无关,您只需在PROC CORR过程中指定它们。

data id;
input id:$4. human alien wizard;
cards;
1005 1 1 0
1018 0 0 1
1022 0 0 1
1024 1 0 0
1034 0 1 0
1069 0 1 0
1078 1 0 0
1247 1 1 1
;;;;
run;

ods output sscp=want;
proc corr  data=id  sscp ;
    var human alien wizard;
run;

proc print data=want;
    format _numeric_ 8.;
run;

结果是:

                   Obs    Variable       human       alien      wizard

                   1      human             4           2           1
                   2      alien             2           4           1
                   3      wizard            1           1           3

答案 2 :(得分:-1)

我能够得到这个答案,虽然它不包括我想要的最后一个单元格(human_alien_wizard):

proc transpose data=FULL_JOIN_ALL3 out=FULL_JOIN_ALL3_v2;
  by employee_id;
  var human_table alien_table wizard_table;
run; 

proc sql;
  create table FULL_JOIN_ALL3_v3 as
  select distinct a._name_ as anm,b._name_ as bnm,
  count(distinct case when a.col1=1 and b.col1=1 then a.employee_id else . end) as smalln
  from FULL_JOIN_ALL3_v2 a, FULL_JOIN_ALL3_v2 b
  where a.employee_id=b.employee_id
  group by anm,bnm
; 

proc tabulate data=FULL_JOIN_ALL3_v3;
 class anm bnm;
 var smalln;
 table anm='',bnm=''*smalln=''*sum=''*f=best3. / rts=5;
run;

enter image description here

相关问题