<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create an edge list in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625712#M18797</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create an edge list from a table that includes the affiliation of each doctor to up to 5 hospitals. Data looks like below:&lt;/P&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.X" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col" width="51px"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="89px"&gt;doctor&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp1&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp2&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp3&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="53px"&gt;hosp4&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="53px"&gt;hosp5&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;1&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003000522&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100072&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;2&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003002106&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100072&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;3&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003004870&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;.&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;4&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003005810&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100128&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;5&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003006552&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100121&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100157&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;6&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003008533&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100018&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100012&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100244&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Doctors and hospitals are all identified by unique codes. In the example above, I have 6 doctors and 7 hospitals (100018,&amp;nbsp;100012,&amp;nbsp;100244,&amp;nbsp;100121,&amp;nbsp;100157,&amp;nbsp;100128, and&amp;nbsp; 100072) . Note that doctor in row 3 are not affiliated with any hospitals.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;I need to create a new table, with 3 columns. First and second column should show pairs of hospitals and the third column show show the number of doctors that are shared between them. In this example, as shown in row 5, hospitals&amp;nbsp;100121 and&amp;nbsp;100157 share 1 physician with each other, also, as shown in row 6, hospitals 100018, 10012 and 100244 each share one physician with each other, therefore the resulting data set should look like this, also please note that in the output, where both hospitals in column 1 and 2 are eqaul, the value in column 3 shows the total number of physicians that are affiliated with that hospital. For example, hospital code&amp;nbsp;100072 has 2 physicians affiliated with it (1003000522 and&amp;nbsp;1003002106)&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Hosp1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hosp2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#Shared_Docs&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100072&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100072&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100128&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100128&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100157&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 18 Feb 2020 22:00:02 GMT</pubDate>
    <dc:creator>niam</dc:creator>
    <dc:date>2020-02-18T22:00:02Z</dc:date>
    <item>
      <title>Create an edge list</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625712#M18797</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create an edge list from a table that includes the affiliation of each doctor to up to 5 hospitals. Data looks like below:&lt;/P&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.X" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col" width="51px"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="89px"&gt;doctor&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp1&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp2&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="58px"&gt;hosp3&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="53px"&gt;hosp4&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="53px"&gt;hosp5&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;1&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003000522&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100072&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;2&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003002106&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100072&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;3&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003004870&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;.&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;4&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003005810&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100128&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;5&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003006552&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100121&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100157&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="51px"&gt;6&lt;/TH&gt;
&lt;TD width="89px" class="l data"&gt;1003008533&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100018&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100012&lt;/TD&gt;
&lt;TD width="58px" class="l data"&gt;100244&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="53px" class="l data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Doctors and hospitals are all identified by unique codes. In the example above, I have 6 doctors and 7 hospitals (100018,&amp;nbsp;100012,&amp;nbsp;100244,&amp;nbsp;100121,&amp;nbsp;100157,&amp;nbsp;100128, and&amp;nbsp; 100072) . Note that doctor in row 3 are not affiliated with any hospitals.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;I need to create a new table, with 3 columns. First and second column should show pairs of hospitals and the third column show show the number of doctors that are shared between them. In this example, as shown in row 5, hospitals&amp;nbsp;100121 and&amp;nbsp;100157 share 1 physician with each other, also, as shown in row 6, hospitals 100018, 10012 and 100244 each share one physician with each other, therefore the resulting data set should look like this, also please note that in the output, where both hospitals in column 1 and 2 are eqaul, the value in column 3 shows the total number of physicians that are affiliated with that hospital. For example, hospital code&amp;nbsp;100072 has 2 physicians affiliated with it (1003000522 and&amp;nbsp;1003002106)&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Hosp1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hosp2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#Shared_Docs&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100072&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100072&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100128&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100128&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100121&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100157&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100244&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 18 Feb 2020 22:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625712#M18797</guid>
      <dc:creator>niam</dc:creator>
      <dc:date>2020-02-18T22:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create an edge list</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625727#M18798</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Obs	doctor	hosp1	hosp2	hosp3	hosp4	hosp5;
cards;
1	1003000522	100072	 	 	 	.
2	1003002106	100072	 	 	 	.
3	1003004870	.	 	 	 	.
4	1003005810	100128	 	 	 	.
5	1003006552	100121	100157	 	 	.
6	1003008533	100018	100012	100244	 	.
;

proc transpose data=have out=temp(drop=_name_ where=(col1 ne .));
by doctor;
var hosp:;
run;

data want ;
 if _n_=1 then do;
  if 0 then set temp(rename=(col1=hosp1)) temp(rename=(col1=hosp2));
  dcl hash H (dataset:'temp(rename=(col1=hosp2))',multidata:'y') ;
  h.definekey  ("doctor") ;
  h.definedata ("hosp2") ;
  h.definedone () ;
 end;
 do Shared_Docs=1 by 1 until(last.hosp1);
  set temp(rename=(col1=hosp1));
  by hosp1 notsorted;
  do until(not _t) ; 
   do rc = h.find() by 0 while (rc = 0) ; 
    h.has_next(result:_t) ;  
    if hosp1=hosp2 then h.removedup() ; 
	if last.hosp1 then output;
    rc=h.find_next();
   end ;
  end ;
 end;
 drop _t rc doctor;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or perhaps a better bet to Sort the transposed dataset before the Hash*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Obs	doctor	hosp1	hosp2	hosp3	hosp4	hosp5;
cards;
1	1003000522	100072	 	 	 	.
2	1003002106	100072	 	 	 	.
3	1003004870	.	 	 	 	.
4	1003005810	100128	 	 	 	.
5	1003006552	100121	100157	 	 	.
6	1003008533	100018	100012	100244	 	.
;

proc transpose data=have out=temp(drop=_name_ where=(col1 ne .));
by doctor;
var hosp:;
run;

proc sort data=temp ;
by col1;
run;

data want ;
 if _n_=1 then do;
  if 0 then set temp(rename=(col1=hosp1)) temp(rename=(col1=hosp2));
  dcl hash H (dataset:'temp(rename=(col1=hosp2))',multidata:'y') ;
  h.definekey  ("doctor") ;
  h.definedata ("hosp2") ;
  h.definedone () ;
 end;
 do Shared_Docs=1 by 1 until(last.hosp1);
  set temp(rename=(col1=hosp1));
  by hosp1 ;
  do until(not _t) ; 
   do rc = h.find() by 0 while (rc = 0) ; 
    h.has_next(result:_t) ;  
    if hosp1=hosp2 then h.removedup() ; 
	if last.hosp1 then output;
    rc=h.find_next();
   end ;
  end ;
 end;
 drop _t rc doctor;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 01:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625727#M18798</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-19T01:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create an edge list</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625772#M18799</link>
      <description>&lt;P&gt;This is really a two-step task:&amp;nbsp; (1) write out all the pairs, and (2) get a frequency of all pairs.&amp;nbsp; The second step is trivial - it's what PROC FREQ is made for.&amp;nbsp; The first step is straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Obs	doctor	hosp1	hosp2	hosp3	hosp4	hosp5;
cards;
1	1003000522	100072	 	 	 	.
2	1003002106	100072	 	 	 	.
3	1003004870	.	 	 	 	.
4	1003005810	100128	 	 	 	.
5	1003006552	100121	100157	 	 	.
6	1003008533	100018	100012	100244	 	.
;

data temp  (keep=obs doctor hosp1 hosp2);
  set have (rename=(hosp1=dummy1 hosp2=dummy2));
  array h {*} dummy1-dummy2 hosp3-hosp5;
  nh=n(of h{*});
  if nh&amp;gt;0;
  do h1=1 to nh;
    do h2=h1 to nh;
      hosp1=min(h{h1},h{h2});
      hosp2=max(h{h1},h{h2});
      output;
    end;
  end;
run;
proc freq data=temp  noprint ;
  tables hosp1 * hosp2 /out=want (keep=hosp1 hosp2 count);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;In the DATA TEMP step, notice I rename HOSP1 and HOSP2 to DUMMY1 DUMMY2 respectively.&amp;nbsp; That's just so I can re-use the names HOSP1 and HOSP2 in the output.&lt;/LI&gt;
&lt;LI&gt;The array is there just to provide a framework for finding all pairs (including self-pairs).&lt;/LI&gt;
&lt;LI&gt;Because the hospitals are not sorted within each observation, you need the MIN and MAX functions when assigning members of each pair to HOSP1 and HOSP2.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 19 Feb 2020 03:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625772#M18799</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-19T03:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create an edge list</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625782#M18800</link>
      <description>&lt;P&gt;Here another option using a hash object.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input Obs doctor hosp1 hosp2 hosp3 hosp4 hosp5;
  cards;
1 1003000522 100072       .
2 1003002106 100072       .
3 1003004870 .       .
4 1003005810 100128       .
5 1003006552 100121 100157     .
6 1003008533 100018 100012 100244   .
;

data _null_;
  if _n_=1 then
    do;
      dcl hash h1(ordered:'y', suminc: 'count');
      h1.defineKey('hospital1','hospital2');
      h1.defineData('hospital1','hospital2','n_docs');
      h1.defineDone();
      retain count 1;
    end;

  set have end=last;
  array hosp {*} hosp1-hosp5;

  do _i=1 to dim(hosp) while(not missing(hosp[_i]));
    hospital1=hosp[_i];
    do _k=_i to dim(hosp) while(not missing(hosp[_k]));
      hospital2=hosp[_k];
      _rc=h1.sum(sum: n_docs);
      n_docs+1;
      _rc=h1.replace();
    end;
  end;

  if last then h1.output(dataset:'want');

run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 206px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36231i96986AE718966DDC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 05:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625782#M18800</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-19T05:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create an edge list</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625862#M18804</link>
      <description>&lt;P&gt;Thank you very much for your help. Your solution worked! I wish I could code like you!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 15:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Create-an-edge-list/m-p/625862#M18804</guid>
      <dc:creator>niam</dc:creator>
      <dc:date>2020-02-19T15:03:25Z</dc:date>
    </item>
  </channel>
</rss>

