<?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: Subset Counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175636#M33729</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My fav is the double proc freq, one because it will give you a list of family/child list, and the second output will be the number of children per family. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=time noprint;&lt;/P&gt;&lt;P&gt;table familynumber*child_id/out=family_child_list;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=family_child_list no print;&lt;/P&gt;&lt;P&gt;table familynumber/out=family_child_count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Oct 2014 22:01:02 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-10-07T22:01:02Z</dc:date>
    <item>
      <title>Subset Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175634#M33727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I am working with a transaction type data set where there are multiple observations for individual children nested within families.&amp;nbsp; Each child has a unique" child_id" and an associated "familynumber." I would like to generate a count of the number of children in each family.&amp;nbsp; There are 746,000 observations from 76,000 families.&amp;nbsp; I have attempted to use the following code, but each of the 76,000 subsets (one for each family) takes about 4 seconds to process.&amp;nbsp; Does anyone know of a more efficient way to go about generating this count variable?&amp;nbsp; Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql noprint;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select left(put(count(distinct(familynumber)),15.0)) into :fmcount work.time;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select distinct(familynumber) into :family1 - :family&amp;amp;fmcount from work.time;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro family_count;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do i = 1 %to &amp;amp;fmcount;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql noprint;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select count(distinct(child_id)) from work.time&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;where familynumber = &amp;amp;&amp;amp;family&amp;amp;i;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend family_count;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%family_count;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 20:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175634#M33727</guid>
      <dc:creator>PhillipSherlock</dc:creator>
      <dc:date>2014-10-07T20:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subset Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175635#M33728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As far as I can see, you don't need macro programming at all to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table familyCounts as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select familyNumber, count(distinct child_id) as childCount&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from time&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by familyNumber;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 21:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175635#M33728</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-10-07T21:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Subset Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175636#M33729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My fav is the double proc freq, one because it will give you a list of family/child list, and the second output will be the number of children per family. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=time noprint;&lt;/P&gt;&lt;P&gt;table familynumber*child_id/out=family_child_list;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=family_child_list no print;&lt;/P&gt;&lt;P&gt;table familynumber/out=family_child_count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 22:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175636#M33729</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-07T22:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subset Counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175637#M33730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No need for double proc freq , just add an option NLEVELS . if I am not making a mistake .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data class;set sashelp.class;run;
proc sort data=class;by sex;run;
ods select NLevels;
ods output NLevels=want;
proc freq data=class nlevels;
by sex;
tables age;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 13:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-Counts/m-p/175637#M33730</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-10-08T13:12:51Z</dc:date>
    </item>
  </channel>
</rss>

