<?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: function count -- specific data counted in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141785#M261618</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok so I think I understand what you are trying to do. I think that step 1 is that you are trying to 1.) get a distinct count of how many lenders there are to each package 2.) get a distinct count of how many lenders in a list are in a package. If this is the case code is below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table lend_in_pack as&lt;/P&gt;&lt;P&gt;select distinct packageid, (count(lenderid)) as numlend /*This counts the number of lenders are in each package*//*If you wanted lenders to be counted once you would add unique( after count and finish it with a )*/&lt;/P&gt;&lt;P&gt;from table1&lt;/P&gt;&lt;P&gt;group by packageid;&lt;/P&gt;&lt;P&gt;create table spec_lend_in_pack as&lt;/P&gt;&lt;P&gt;select distinct packageid, (sum(case when lenderid in (50 74 78 /*All of the other lenderids in here*/) then 1 else 0 end)) as spec_lend /*This takes the list of specific lenderids and outputs a 1 or 0 if it is in the list, then sums the list to give you your count, once again this isn't taking distinct lenderids so if one shows up 5 times, it will be counted 5 times, if you wanted specific ones, I would recommend just creating a table that only gives you distinct rows by running a select distinct * from table1 and then running this code again*/&lt;/P&gt;&lt;P&gt;from table1&lt;/P&gt;&lt;P&gt;group by packageid;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jan 2014 18:16:32 GMT</pubDate>
    <dc:creator>overmar</dc:creator>
    <dc:date>2014-01-15T18:16:32Z</dc:date>
    <item>
      <title>function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141779#M261612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem is pretty basic (again) but it is very specific.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to count the number of lenders in each package. Each package and lender are identified by a number (PackageID and LenderID).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If my request finishes here, my code would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;create table2 as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;select *, count(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderID) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; nombparticipant&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;from table1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;group by PackageID&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;order by PackageID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;But I want to count the number of specific LenderIDs. I'm interessed in LenderID 500, 523, 1701, ... (total: 20 different LenderID).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;I want to know how many of them are in each package.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;How can I consider my twenty LenderIDs with the function count?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 160px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;/TR&gt;&lt;TR&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" width="80"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PackageID&lt;/P&gt;&lt;/TD&gt;&amp;nbsp; &lt;TD class="xl64" width="80"&gt;LenderID&lt;/TD&gt;&lt;/TR&gt; (This is what my table looks like at the start.)&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;78&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;34&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;61&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;56&lt;/TD&gt;&lt;TD class="xl63"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;78&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;52&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;84&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;59&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;56&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;74&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;46&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;64&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;74&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;74&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;69&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;28&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;72&lt;/TD&gt;&lt;TD class="xl63"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20"&gt;…&lt;/TD&gt;&lt;TD class="xl63"&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 14:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141779#M261612</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-15T14:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141780#M261613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand your requirement then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where LenderId in ( your list of Ids)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after your From clause might work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 14:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141780#M261613</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-01-15T14:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141781#M261614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code works, but it doesn't do the function count (i.e. I have a whole column of zeros even if it is not the right result).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will try to figure out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 15:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141781#M261614</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-15T15:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141782#M261615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table table2 as&lt;/P&gt;&lt;P&gt;select *&amp;nbsp; count(&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderID) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderID &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderIDs) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; nombLenderIDCAN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;from table 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;group by PackageID&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;order by PackageID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Before, I have created an excel file for the twenty LenderID. I have imported to SAS. It is my table LenderIDs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 16:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141782#M261615</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-15T16:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141783#M261616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;It seems that I must change brackets:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;count(distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderID &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderID &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; LenderIDs)) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; nombLenderIDCAN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 16:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141783#M261616</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-15T16:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141784#M261617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an error again. Sometimes, 1 appears when it should be 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will figure out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 16:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141784#M261617</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-15T16:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141785#M261618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok so I think I understand what you are trying to do. I think that step 1 is that you are trying to 1.) get a distinct count of how many lenders there are to each package 2.) get a distinct count of how many lenders in a list are in a package. If this is the case code is below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table lend_in_pack as&lt;/P&gt;&lt;P&gt;select distinct packageid, (count(lenderid)) as numlend /*This counts the number of lenders are in each package*//*If you wanted lenders to be counted once you would add unique( after count and finish it with a )*/&lt;/P&gt;&lt;P&gt;from table1&lt;/P&gt;&lt;P&gt;group by packageid;&lt;/P&gt;&lt;P&gt;create table spec_lend_in_pack as&lt;/P&gt;&lt;P&gt;select distinct packageid, (sum(case when lenderid in (50 74 78 /*All of the other lenderids in here*/) then 1 else 0 end)) as spec_lend /*This takes the list of specific lenderids and outputs a 1 or 0 if it is in the list, then sums the list to give you your count, once again this isn't taking distinct lenderids so if one shows up 5 times, it will be counted 5 times, if you wanted specific ones, I would recommend just creating a table that only gives you distinct rows by running a select distinct * from table1 and then running this code again*/&lt;/P&gt;&lt;P&gt;from table1&lt;/P&gt;&lt;P&gt;group by packageid;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 18:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141785#M261618</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2014-01-15T18:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: function count -- specific data counted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141786#M261619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I finally create a new table like you suggest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 19:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-count-specific-data-counted/m-p/141786#M261619</guid>
      <dc:creator>windyboo</dc:creator>
      <dc:date>2014-01-17T19:52:13Z</dc:date>
    </item>
  </channel>
</rss>

