<?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: Remerge-using Have or WHERE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787269#M251530</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does NOT work :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select   Name , Sex
	   , mean(Height) as average_Height
from sashelp.class
where Height &amp;lt; calculated average_Height
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this works well :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select   Name , Sex
	   , mean(Height) as average_Height
from sashelp.class
having Height &amp;lt; average_Height
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Thu, 23 Dec 2021 17:31:13 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-12-23T17:31:13Z</dc:date>
    <item>
      <title>Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787266#M251527</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In this code using Re-merging technique.&lt;/P&gt;
&lt;P&gt;I wonder if need to use WHERE clause or HAVING clause in order to choose only students with Math score below overall mean on Math.&lt;/P&gt;
&lt;P&gt;Please note tht I haven't run this code and asked a theoretical question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select Gender,
	mean(Math) as average_Math
from ttt
WHERE  Math&amp;lt;average_Math
;
QUIT;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 17:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787266#M251527</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T17:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787267#M251528</link>
      <description>&lt;P&gt;If you make up a simple data set, you can find the answer yourself.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 17:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787267#M251528</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-23T17:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787268#M251529</link>
      <description>Did you test your theory?&lt;BR /&gt;What happened?</description>
      <pubDate>Thu, 23 Dec 2021 17:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787268#M251529</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-23T17:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787269#M251530</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does NOT work :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select   Name , Sex
	   , mean(Height) as average_Height
from sashelp.class
where Height &amp;lt; calculated average_Height
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this works well :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select   Name , Sex
	   , mean(Height) as average_Height
from sashelp.class
having Height &amp;lt; average_Height
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 17:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787269#M251530</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-12-23T17:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787271#M251532</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In this code using Re-merging technique.&lt;/P&gt;
&lt;P&gt;I wonder if need to use WHERE clause or HAVING clause in order to choose only students with Math score below overall mean on Math.&lt;/P&gt;
&lt;P&gt;Please note tht I haven't run this code and asked a theoretical question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Create table Wanted  AS
select Gender,
	mean(Math) as average_Math
from ttt
WHERE  Math&amp;lt;average_Math
;
QUIT;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Gosh, I also hate the idea of using PROC SQL for EVERYTHING, especially statistical things (although certainly PROC SQL can do this). There are plenty of other ways to answer this question which would be helpful to learn, and would show nice growth if people branched out from SQL into other SAS PROCs. This also has a lot more power in the long run and for real-world problems. I have this problem in my group (so this isn't directed at anyone in particular)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=sashelp.class method=mean sprefix=delta_ out=want(where=(delta_height&amp;lt;0));
    var height;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 17:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787271#M251532</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-23T17:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787276#M251535</link>
      <description>May you please  explain why dinyiu hate using re-meege via proc sql?&lt;BR /&gt;As I understand  this ability exists only in sas and cannot be done in Microsoft sql language.</description>
      <pubDate>Thu, 23 Dec 2021 18:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787276#M251535</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T18:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787279#M251538</link>
      <description>It's not appropriate for the use case you've shown but it has it's purposes. &lt;BR /&gt;</description>
      <pubDate>Thu, 23 Dec 2021 19:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787279#M251538</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-23T19:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787283#M251541</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May you please explain why dinyiu hate using re-meege via proc sql?&lt;BR /&gt;As I understand this ability exists only in sas and cannot be done in Microsoft sql language.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I already explained why I feel the way I do.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 19:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787283#M251541</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-23T19:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Remerge-using Have or WHERE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787310#M251549</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;, Your question per se is good, albeit warrants a tutorial approach than a short explanation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Short answer:&lt;/P&gt;
&lt;P&gt;HAVING clause in general applies for conditional&amp;nbsp;&lt;EM&gt;vertical&lt;/EM&gt; processing for columns as a whole or for BY groups using a summary function, whereas the WHERE clause strictly is not designed and is incompatible for vertical column summary. Therefore WHERE isn't for summary and then filter, rather you could deem this a mere row filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To begin with, some teaser&amp;nbsp;for you to figure why both HAVING and WHERE for a calculated column works below-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Using calculated &amp;amp; WHERE */
PROC SQL;
Create table Wanted  AS
select   *,mean(100, weight) as w
from sashelp.class
where  calculated w &amp;lt; 100
;
QUIT;

/*Using HAVING*/
PROC SQL;
Create table Wanted  AS
select   *,mean(100, weight) as w
from sashelp.class
having   w &amp;lt; 100
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tips- 1. Think about how a SQL processor works i.e. read from disk, buffer, memory(cache), processing 2. Timing - what executes when(before or after) 3. Why there's no REMERGE in the above example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will try and come back with a detailed explanation if my boss gives me some time off. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; lol&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 23:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remerge-using-Have-or-WHERE/m-p/787310#M251549</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-12-23T23:06:31Z</dc:date>
    </item>
  </channel>
</rss>

