<?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: Implement family composition table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591106#M169282</link>
    <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id person $ ;
cards;
1 man
1 female
1 child
2 man
2 female
2 child
3 man
3 female
3 child
4 man
4 female
4 child
5 man
5 child
6 man
6 child
6 female
6 child
6 child
7 female
7 child
8 female
8 child
9 female
9 child
9 child
9 child
10 man
10 female
11 man
12 female
13 child
13 child
13 child
;
run;

proc sort data = have;
by id descending person;
run;

data tmp;
set have;
by ID;
length type $ 20; retain type;
if first.id then type = " ";
type = catx(" ", type, lowcase(char(person, 1)));
if last.id then 
do;
  type = catx(","
          ,ifc(index(type, "m"), "M", "no M")
          ,ifc(index(type, "f"), "F", "no F")
          ,ifc(index(type, "c"), "C", "no C")
          );
  output; 
end;
run;

proc tabulate data = tmp;
class type;
table N, type;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 24 Sep 2019 08:29:42 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2019-09-24T08:29:42Z</dc:date>
    <item>
      <title>Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/590897#M169188</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Basically what I have as a dataset is a table with different types of people (man, female, child) in families which have same ID (for example a family with parent + child,&amp;nbsp; there would be the same ID).&lt;/P&gt;&lt;P&gt;What I need to produce is a frequency dataset, where I give the frequency of differently composed families (child + 2 parents, 2 parents + no child or 1 person without children). So the end table would have 2 lines a 3 cols, and the "have" dataset is a table with family id, and "gender" (m/f/child).&lt;/P&gt;&lt;P&gt;Thanks and hope it was clear enough haha.&lt;/P&gt;&lt;P&gt;I would post code but it really wouldnt be constructive as i really don't have any clue on how to do this...&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 13:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/590897#M169188</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-09-23T13:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/590925#M169201</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do you mean something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id person $ ;
cards;
1 man
1 female
1 child
2 man
2 female
2 child
3 man
3 female
3 child
4 man
4 female
4 child
5 man
5 child
6 man
6 child
6 female
6 child
6 child
7 female
7 child
8 female
8 child
9 female
9 child
9 child
9 child
;
run;

proc sort data = have;
by id descending person;
run;

data tmp;
set have;
by ID;
length type $ 20; retain type;
if first.id then type = " ";
type = catx(" ", type, char(person, 1));
if last.id then output; 
run;

proc tabulate data = tmp;
class type;
table type, N;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 14:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/590925#M169201</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-23T14:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591100#M169277</link>
      <description>&lt;P&gt;what i need at the end is something like this:&lt;BR /&gt;M + F + C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | M+F no C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| M, no F, no C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; | no M, F, no C&lt;BR /&gt;nb of fams with M+F+C | nb fams with M+F no C&amp;nbsp; |&amp;nbsp; &amp;nbsp;nb fams with M no F no C&amp;nbsp; | nb fams with F, but no M and no C&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M being the male parent, F being the female parent and C being the child.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each family has same ID (a number).&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 08:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591100#M169277</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-09-24T08:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591103#M169279</link>
      <description>btw your thing works, and thanks a lot, but it displays all these "M F C" lines&lt;BR /&gt;thanks</description>
      <pubDate>Tue, 24 Sep 2019 08:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591103#M169279</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-09-24T08:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591106#M169282</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id person $ ;
cards;
1 man
1 female
1 child
2 man
2 female
2 child
3 man
3 female
3 child
4 man
4 female
4 child
5 man
5 child
6 man
6 child
6 female
6 child
6 child
7 female
7 child
8 female
8 child
9 female
9 child
9 child
9 child
10 man
10 female
11 man
12 female
13 child
13 child
13 child
;
run;

proc sort data = have;
by id descending person;
run;

data tmp;
set have;
by ID;
length type $ 20; retain type;
if first.id then type = " ";
type = catx(" ", type, lowcase(char(person, 1)));
if last.id then 
do;
  type = catx(","
          ,ifc(index(type, "m"), "M", "no M")
          ,ifc(index(type, "f"), "F", "no F")
          ,ifc(index(type, "c"), "C", "no C")
          );
  output; 
end;
run;

proc tabulate data = tmp;
class type;
table N, type;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 08:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591106#M169282</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-24T08:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591110#M169285</link>
      <description>&lt;P&gt;hello again and thanks for quick response!&lt;/P&gt;&lt;P&gt;i was able to do this, i'm almost finished i just need to set lines as cols and cols as lines.&lt;/P&gt;&lt;P&gt;what i did was set the max length of type to 5 so i would only get the composition as (M F C). then i made a format and applied it to the dataset and removed every row which contained errors (family with just child for example)&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 08:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591110#M169285</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-09-24T08:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Implement family composition table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591112#M169287</link>
      <description>&lt;P&gt;That last proc tabulate reverses cols and rows,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first one was: "table type,N;" the newer one is "table N,type".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need "transposed" dataset then use proc transpose ( &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p1r2tjnp8ewe3sn1acnpnrs3xbad.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p1r2tjnp8ewe3sn1acnpnrs3xbad.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data = tmp output = tmp2(keep = type N);
class type;
table N, type;
run;

proc transpose data = tmp2 out = tmp3;
var N;
id type;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 09:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Implement-family-composition-table/m-p/591112#M169287</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-24T09:10:17Z</dc:date>
    </item>
  </channel>
</rss>

