<?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: Proc SQL count by group when using GE in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758287#M30194</link>
    <description>&lt;P&gt;Well, first of all, I would switch a lot of the Having clause (which occurs &lt;EM&gt;after&lt;/EM&gt; initial row selection) to the Where clause which screens out rows as part of the initial selection.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count(table_name.column_name) should be correct.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 21:39:01 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-07-29T21:39:01Z</dc:date>
    <item>
      <title>Proc SQL count by group when using GE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758281#M30193</link>
      <description>&lt;P&gt;I have 3 tables:&lt;BR /&gt;Orders (Cust_ID, Order_Number, PN, Cost)&lt;BR /&gt;Parts (PN, Part_Name)&lt;BR /&gt;Customers (Cust_ID, Cust_Name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cust_ID in the Orders table is equal to Cust_ID in the Customers table.&lt;BR /&gt;PN in the Orders table is equal to PN in the Parts table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Proc SQL I need a table with the first column grouped by "Cust_Name" and the second column the times (count) that each Cust_Name has made an order where the "Cost" is greater than 1000 and the "Part_Name" is equal to "Oring".&lt;/P&gt;&lt;P&gt;The result should come out:&lt;BR /&gt;Cust_Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Count Orders Greater than 1000 &amp;amp; Part_Name = Oring&lt;BR /&gt;Name1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;Name2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;BR /&gt;......&lt;/P&gt;&lt;P&gt;3 and 5 mean that Name1 made 3 orders each greater than 1000 and Name2 made 5 orders each greater than 1000 and these 8 orders correspond to the Part_Name "Oring".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following schematic but can't finish it to show me the count:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;select Customers.Cust_Name&lt;BR /&gt;from Orders, Parts, Customers&lt;BR /&gt;group by Customers.Cust_Name&lt;BR /&gt;having&lt;BR /&gt;Orders.PN = Parts.PN&lt;BR /&gt;and&lt;BR /&gt;Orders.Cust_ID = Customers.Cust_ID&lt;BR /&gt;and&lt;BR /&gt;Orders.Cost ge 1000&lt;BR /&gt;and&lt;BR /&gt;Parts.Part_Name = 'Oring';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am missing the syntax for it to display the second column (count), I used Count (*), Count (Orders.Cost), Count (Customers.Cust_Name), but none worked for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/229423"&gt;@Count&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 21:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758281#M30193</guid>
      <dc:creator>Will2801</dc:creator>
      <dc:date>2021-07-29T21:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count by group when using GE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758287#M30194</link>
      <description>&lt;P&gt;Well, first of all, I would switch a lot of the Having clause (which occurs &lt;EM&gt;after&lt;/EM&gt; initial row selection) to the Where clause which screens out rows as part of the initial selection.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count(table_name.column_name) should be correct.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 21:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758287#M30194</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T21:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count by group when using GE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758288#M30195</link>
      <description>&lt;P&gt;I might re-vamp the code like the below.&amp;nbsp; Notice that there's a WHERE clause now.&amp;nbsp; Again, the WHERE clause screens out any rows that don't meet your criteria&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the initial results set is obtained.&amp;nbsp; Then, the count will only count those rows that match the criteria, and the&amp;nbsp;GROUP BY clause will act as a BY statement would in a Data step, i.e. to cause the count to occur at the Customer level.&amp;nbsp; Notice that I've shortened the table names by using a three letter alias for ease of coding (and reading I think).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that "Oring" is case sensitive.&amp;nbsp; If you don't want it to be case sensitive you could use either Lowcase(Part_Name) = 'oring' or Upcase(Part_Name) = 'ORING'.&amp;nbsp; Note also that O-Ring does not equal ORing.&amp;nbsp; If your data is really clean, this shouldn't be a problem, but it's something to be aware of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
	select	Customers.Cust_Name
		,COUNT(*)			AS	Order_Count
		from	Orders		Ord
				,Parts		Prt
				,Customers	Cst
	WHERE	Ord.PN 			=	Prt.PN
		and	Ord.Cst_ID 		=	Cst.Cust_ID
		and	Ord.Cost		ge	1000
		and	Prt.Part_Name	=	'Oring'
		group by Cst.Cust_Name
		;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 21:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758288#M30195</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T21:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count by group when using GE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758294#M30197</link>
      <description>&lt;P&gt;thanks a lot&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;,&amp;nbsp;I was confusing the HAVING and WHERE clauses, but thanks to your answer the figure is now clearer. I'm just starting out in SAS and his comment helped me a lot.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 23:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-count-by-group-when-using-GE/m-p/758294#M30197</guid>
      <dc:creator>Will2801</dc:creator>
      <dc:date>2021-07-29T23:00:48Z</dc:date>
    </item>
  </channel>
</rss>

