<?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 How do I create a wide file of IDs? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913694#M360098</link>
    <description>&lt;P&gt;I received participant data from 3 independent research sites. If an individual was seen at multiple sites, they will have received a different ID from each site. In order to identify which participants are the same individuals across sites, I ran their demographic info through a probabilistic matching software that compares two records at a time. The software outputs a file like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input subjectid_1 subjectid_2;
 cards;
1 5
2 7
3 6
4 5
7 8
;
run; 
*For example, subjects 1 and 5 are the same person.;&lt;BR /&gt;*Notes: &lt;BR /&gt; 1) The sites do not use each other's IDs (e.g. SUBJECTID_1=7 is definitely the same person as SUBJECTID_2=7)&lt;BR /&gt; 2) Assume the matching software results are correct.&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I now want any given individual to only be counted in one row, with all their IDs listed in the columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 input subjectid_1 subjectid_2 subjectid_3;
 cards;
1 5 4
2 7 8
3 6
;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to do this? After it's organized this way, I can assign them my own standardized ID and know how many unique individuals there are.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 23:38:49 GMT</pubDate>
    <dc:creator>bkq32</dc:creator>
    <dc:date>2024-01-30T23:38:49Z</dc:date>
    <item>
      <title>How do I create a wide file of IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913694#M360098</link>
      <description>&lt;P&gt;I received participant data from 3 independent research sites. If an individual was seen at multiple sites, they will have received a different ID from each site. In order to identify which participants are the same individuals across sites, I ran their demographic info through a probabilistic matching software that compares two records at a time. The software outputs a file like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input subjectid_1 subjectid_2;
 cards;
1 5
2 7
3 6
4 5
7 8
;
run; 
*For example, subjects 1 and 5 are the same person.;&lt;BR /&gt;*Notes: &lt;BR /&gt; 1) The sites do not use each other's IDs (e.g. SUBJECTID_1=7 is definitely the same person as SUBJECTID_2=7)&lt;BR /&gt; 2) Assume the matching software results are correct.&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I now want any given individual to only be counted in one row, with all their IDs listed in the columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 input subjectid_1 subjectid_2 subjectid_3;
 cards;
1 5 4
2 7 8
3 6
;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to do this? After it's organized this way, I can assign them my own standardized ID and know how many unique individuals there are.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 23:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913694#M360098</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2024-01-30T23:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a wide file of IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913708#M360104</link>
      <description>&lt;P&gt;After searching the forum a bit I found code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;proposed for a similar problem&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Connecting-different-observations-based-on-the-values-that-two/td-p/355793" target="_self"&gt;here&lt;/A&gt; that should return what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input from to;
  cards;
1 5
2 7
3 6
4 5
7 8
;

data full;
  set have end=last;

  if _n_ eq 1 then
    do;
      declare hash h();
      h.definekey('node');
      h.definedata('node');
      h.definedone();
    end;

  output;
  node=from;
  h.replace();
  from=to;
  to=node;
  output;
  node=from;
  h.replace();

  if last then
    h.output(dataset:'node');
  drop node;
run;

data want(keep=node group_id);
  declare hash ha(ordered:'a');
  declare hiter hi('ha');
  ha.definekey('count');
  ha.definedata('last');
  ha.definedone();
  declare hash _ha(hashexp: 20);
  _ha.definekey('key');
  _ha.definedone();

  if 0 then set full;
  declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
  from_to.definekey('from');
  from_to.definedata('to');
  from_to.definedone();

  if 0 then set node;
  declare hash no(dataset:'node');
  declare hiter hi_no('no');
  no.definekey('node');
  no.definedata('node');
  no.definedone();

  do while(hi_no.next()=0);
    group_id+1;
    output;
    count=1;
    key=node;
    _ha.add();
    last=node;
    ha.add();
    rc=hi.first();

    do while(rc=0);
      from=last;
      rx=from_to.find();

      do while(rx=0);
        key=to;
        ry=_ha.check();

        if ry ne 0 then
          do;
            node=to;
            output;
            rr=no.remove(key:node);
            key=to;
            _ha.add();
            count+1;
            last=to;
            ha.add();
          end;

        rx=from_to.find_next();
      end;

      rc=hi.next();
    end;

    ha.clear();
    _ha.clear();
  end;

  stop;
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="Patrick_0-1706667091315.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93086iBEDD3CA3BC12FC75/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1706667091315.png" alt="Patrick_0-1706667091315.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 02:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913708#M360104</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-31T02:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a wide file of IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913885#M360153</link>
      <description>&lt;P&gt;This is awesome - thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;and&amp;nbsp;@Ksharp!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 21:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-wide-file-of-IDs/m-p/913885#M360153</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2024-01-31T21:09:12Z</dc:date>
    </item>
  </channel>
</rss>

