<?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 Re: Is family construction possible? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688215#M209025</link>
    <description>&lt;P&gt;Thank you Jim. This is great use of temporary arrays that I haven't used much yet.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2020 14:26:49 GMT</pubDate>
    <dc:creator>mk123451243</dc:creator>
    <dc:date>2020-10-01T14:26:49Z</dc:date>
    <item>
      <title>Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688087#M208970</link>
      <description>Let’s say I own a restaurant in an area with only three families. each with four members. Let’s identify each family&lt;BR /&gt;by a group of four letters that represent each person with a family.&lt;BR /&gt;Family 1&lt;BR /&gt;A B C D&lt;BR /&gt;Family 2&lt;BR /&gt;E F G H&lt;BR /&gt;Family 3&lt;BR /&gt;I J K L&lt;BR /&gt;&lt;BR /&gt;Each night, for eight nights, two or three people arrive at the restaurant. Guests are recorded in the order they enter the restaurant. All guests on any given night are from ONE family only. The resulting observation set for all eight nights is:&lt;BR /&gt;&lt;BR /&gt;A B C&lt;BR /&gt;E G .&lt;BR /&gt;D B .&lt;BR /&gt;K L .&lt;BR /&gt;I K .&lt;BR /&gt;F G .&lt;BR /&gt;E G H&lt;BR /&gt;L J .&lt;BR /&gt;&lt;BR /&gt;Now I ask, is there are a way to reconstruct the families by grouping letters into complete families given the eight observations?&lt;BR /&gt;&lt;BR /&gt;There is a clear algorithm but it is unclear if it is possible in SAS. I have no reason to doubt that it is.&lt;BR /&gt;&lt;BR /&gt;The algorithm involves setting the first observation as a family and comparing it to all other observations. If there are any shared people, then all people in those observations are aggregated to expand the original family. Then repeat for for each observation.&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Oct 2020 03:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688087#M208970</guid>
      <dc:creator>mk123451243</dc:creator>
      <dc:date>2020-10-01T03:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688095#M208972</link>
      <description>&lt;P&gt;I'm sure there's any number of ways to do it, but here's one that builds an array for each family and then use the IN operator to check which family the first diner is a member of.&amp;nbsp; The "Family" variable is set based on the first diner.&amp;nbsp; Only one diner is needed to identify the family.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Families;
	ARRAY	FAMILY1	[4] $8 _temporary_ ('A' 'B' 'C' 'D');
	ARRAY	FAMILY2	[4] $8 _temporary_ ('E' 'F' 'G' 'H');
	ARRAY	FAMILY3	[4] $8 _temporary_ ('I' 'J' 'K' 'L');

	INPUT	Person1 $
			Person2	$
			Person3	$
			;

	IF	Person1	IN	FAMILY1	THEN
		Family	=	1;
	ELSE
	IF	Person1	IN	FAMILY2	THEN
		Family	=	2;
	ELSE
	IF	Person1	IN	FAMILY3	THEN
		Family	=	3;

DATALINES;
A B C
E G .
D B .
K L .
I K .
F G .
E G H
L J .
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601524000621.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50034iE63984E37AB2764F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601524000621.png" alt="jimbarbour_0-1601524000621.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 03:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688095#M208972</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T03:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688097#M208973</link>
      <description>&lt;P&gt;Families are connected components. SAS has a proc to find those:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data visits;
input (g1-g3) ($);
datalines;
A B C
E G .
D B .
K L .
I K .
F G .
E G H
L J .
;

data links;
set visits;
array a g:;
do i = 2 to dim(a);
    if not missing(a{i}) then do;
        from = a{i-1};
        to = a{i};
        output;
        end;
    end;
keep from to;
run;

proc optnet data_links=links direction=undirected out_nodes=nodes;
concomp;
run;

proc sort data=nodes; by concomp node; run;

data families;
do until(last.concomp);
    set nodes; by concomp;
    length members $20;
    members = catx(" ", members, node);
    end;
rename concomp=family;
drop node;
run;

proc print data=families noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 99px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50035iE4FBB08F41F41178/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 03:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688097#M208973</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-10-01T03:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688215#M209025</link>
      <description>&lt;P&gt;Thank you Jim. This is great use of temporary arrays that I haven't used much yet.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 14:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688215#M209025</guid>
      <dc:creator>mk123451243</dc:creator>
      <dc:date>2020-10-01T14:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688218#M209027</link>
      <description>&lt;P&gt;Awesome! This is exactly what I needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A way to reconstruct the families assuming I have no prior information about the families.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 14:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688218#M209027</guid>
      <dc:creator>mk123451243</dc:creator>
      <dc:date>2020-10-01T14:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Is family construction possible?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688280#M209050</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92121"&gt;@mk123451243&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In particular, I like the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;IF Person &lt;STRONG&gt;IN&lt;/STRONG&gt; Family&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;coding structure that an array allows.&amp;nbsp; Notice that I don't have to subscript through the array or ever go down to the individual values in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's hard to argue with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;approach that not only can tell you which family dined but also define the families for you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 16:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-family-construction-possible/m-p/688280#M209050</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-01T16:18:11Z</dc:date>
    </item>
  </channel>
</rss>

