- /*建立原始数据集test*/
- data test;
- input (compa compb) (:$20.);
- cards;
- 脸书 中石化
- 苹果 中石化
- ibm 苹果
- ibm 高盛
- att 德州
- 德州 中石油
- ;
- run;
- /*
- 在数据集test基础上,生成数据集test1,
- 新设2个变量a和b,把变量compa和compb的值摞在一起
- (变量a和b其实是一样的,compa和compb接下来不会用到了),
- a、b的主要目的是用于找出所有出现的节点(根据变量a或b),
- 以及网络划分时候找出与每个节点连接的节点
- (前提是compa和compb的关系没有方向)*/
- data test1;
- length
- a $20
- b $20;
- set test;
- a=compa;
- b=compb;
- output;
- a=compb;
- b=compa;
- output;
- run;
- /*数据集test1按变量a排序,这一步无关紧要*/
- proc sort data=test1;
- by a;
- run;
- /*根据数据集test1中的变量a(或变量b),新建数据集notes,
- 储存所有出现的节点,具体储存在变量名note_name中*/
- proc sql;
- create table notes as
- select distinct a as note_name
- from test1;
- run;
- quit;
- /*在数据集notes基础上,复制note_name变量,
- 命名为temp,temp变量用于网络划分时候归类。
- 另外把所有出现的节点数赋值给宏变量&n。*/
- data notes;
- length temp $20;
- set notes end=last;
- temp=note_name;
- if last then call symput('n',_n_);
- run;
- /*
- 网络划分的大概思想是在数据集notes的temp变量里选一个节点,
- 根据数据集test1的变量a、b,找出与这个节点连接的其他节点,
- 后者(与这个节点连接的其他节点)用前者(这个节点)代替
- (具体操作时数据集test1中的变量a和b,分别做变量值替换;
- 数据集notes中的变量temp,做变量值替换),
- 根据所有出现的节点数(&n)遍历后,
- 数据集notes中变量temp的值域数量,就是网络数,
- 而变量note_name则记录着原始节点名称。
- */
- /*根据所有出现的节点数(&n)遍历*/
- %macro test;
- %do i=1 %to &n;
- /*在数据集notes的temp变量里选一个节点*/
- data _null_;
- set notes;
- if _n_=&i then call symput('note_name',temp);
- run;
- /*根据数据集test1的变量a、b,找出与这个节点连接的其他节点,
- 存在数据集temp_one_note中*/
- proc sql;
- create table temp_one_note as
- select distinct b from test1
- where a="¬e_name";
- run;
- quit;
- /*为了方便,把“与这个节点连接的其他节点”存入宏变量&one_note*/
- proc sql noprint;
- select distinct b into : one_note separated by ' '
- from temp_one_note;
- run;
- quit;
- /*数据集test1中的变量a和b,分别做变量值替换*/
- data test1;
- set test1;
- %do j=1 %to %sysfunc(countw(&one_note));
- if a=scan("&one_note",&j) then a="¬e_name";
- if b=scan("&one_note",&j) then b="¬e_name";
- %end;
- /*数据集notes中的变量temp,做变量值替换*/
- data notes;
- set notes;
- %do j=1 %to %sysfunc(countw(&one_note));
- if temp=scan("&one_note",&j) then temp="¬e_name";
- %end;
- run;
- %end;
- %mend;
- %test
- /*网络内节点全排列*/
- proc sql;
- create table want as
- select t1.note_name as comp1, t2.note_name as comp2 from notes as t1, notes as t2
- where t1.temp=t2.temp;
- run;
- quit;
- data want;
- set want;
- if comp1^=comp2;
- run;


雷达卡






京公网安备 11010802022788号







