<?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: Top 10 Table with counts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456267#M70080</link>
    <description>&lt;P&gt;Something like this - untested?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have
          out = want1 nodupkey;
  by CompName ClientID;
run;

proc sql;
  create table want2 (obs = 10) as
  select CompName
        ,count(*) as Client_Count
  from want1
  group by CompName
  order by descending Client_Count
  ;
quit;



           ,&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 22 Apr 2018 06:57:53 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2018-04-22T06:57:53Z</dc:date>
    <item>
      <title>Top 10 Table with counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456261#M70079</link>
      <description>&lt;P&gt;I'm trying to create a table that calculates the top 10 companies based on the number of unique clients they have. I have a CompanyName variable,&amp;nbsp;a ClientID variable, and a ProjectID variable, so there are, for example, 10 observations for Company ABC &amp;nbsp;because they have 6&amp;nbsp;client IDs they are working with for a total of 10 different projects (so some of the clients are repeated but I only want to count each unique client). I am not trying to calculate projects, just the number of unique clients for each company and then sorting by the company with the most clients to create the top 10 list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data set looks something like:&lt;/P&gt;&lt;P&gt;&lt;U&gt;CompName. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ClientID. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ProjectID&lt;/U&gt;&lt;/P&gt;&lt;P&gt;CompanyABC. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0022&lt;/P&gt;&lt;P&gt;CompanyABC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0023&lt;/P&gt;&lt;P&gt;CompanyABC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 235 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0042&lt;/P&gt;&lt;P&gt;CompanyDEF &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;152 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0074&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ultimately, I want something along the lines of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Company &amp;nbsp; &amp;nbsp; Client Count&lt;/U&gt;&lt;/P&gt;&lt;P&gt;CompABC &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2&lt;/P&gt;&lt;P&gt;CompDEF &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;CompXYZ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried proc summary, report, print, frequent, and sql...I can't seem to get a table that has more than the first observation (which is not even one of the "top" companies).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated!&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 05:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456261#M70079</guid>
      <dc:creator>slobber</dc:creator>
      <dc:date>2018-04-22T05:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 Table with counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456267#M70080</link>
      <description>&lt;P&gt;Something like this - untested?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have
          out = want1 nodupkey;
  by CompName ClientID;
run;

proc sql;
  create table want2 (obs = 10) as
  select CompName
        ,count(*) as Client_Count
  from want1
  group by CompName
  order by descending Client_Count
  ;
quit;



           ,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Apr 2018 06:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456267#M70080</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-04-22T06:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 Table with counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456283#M70081</link>
      <description>&lt;P&gt;You can use distinct count and OUTOBS= to limit the output dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt;infile datalines dlm=" " dsd;&lt;BR /&gt;input CompName :$ ClientID ProjectID :$;&lt;BR /&gt;datalines;&lt;BR /&gt;CompanyABC 123 0022&lt;BR /&gt;CompanyABC 123 0023&lt;BR /&gt;CompanyABC 235 0042&lt;BR /&gt;CompanyABC 234 0042&lt;BR /&gt;CompanyDEF 52 0074&lt;BR /&gt;CompanyDEF 123 0001&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sql outobs=1;&lt;BR /&gt;Create table want as&lt;BR /&gt;select CompName,count(distinct ClientID) as Client_Count&lt;BR /&gt;from have&lt;BR /&gt;group by CompName&lt;BR /&gt;order by Client_Count desc ;&lt;BR /&gt;quit;&lt;BR /&gt; &amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;I don't this obs= is a valid option in PROC SQL. Correct me if I'm wrong.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 13:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456283#M70081</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-22T13:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 Table with counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456301#M70083</link>
      <description>&lt;P&gt;Yes, this worked. Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 15:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456301#M70083</guid>
      <dc:creator>slobber</dc:creator>
      <dc:date>2018-04-22T15:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 Table with counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456337#M70084</link>
      <description>&lt;P&gt;Then please mark post as answered.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 21:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Top-10-Table-with-counts/m-p/456337#M70084</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-04-22T21:14:17Z</dc:date>
    </item>
  </channel>
</rss>

