<?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 SQL where statement using alias column in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54464#M15081</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I as surprised to find that I could use a column alias in my where statement.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table xxx as&lt;/P&gt;&lt;P&gt;select one, two, three&lt;/P&gt;&lt;P&gt;from dset&lt;/P&gt;&lt;P&gt;where one =1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table yyy as&lt;/P&gt;&lt;P&gt;select one as flag, two, three&lt;/P&gt;&lt;P&gt;from dset&lt;/P&gt;&lt;P&gt;where flag = 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do these statements both yield these same result?&amp;nbsp; If soon, is this documented somewhere.&amp;nbsp; I have found these documentation for using caculated values in a where statements but not for using these column alias in these where statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Nov 2011 17:39:15 GMT</pubDate>
    <dc:creator>kas</dc:creator>
    <dc:date>2011-11-25T17:39:15Z</dc:date>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54464#M15081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I as surprised to find that I could use a column alias in my where statement.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table xxx as&lt;/P&gt;&lt;P&gt;select one, two, three&lt;/P&gt;&lt;P&gt;from dset&lt;/P&gt;&lt;P&gt;where one =1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table yyy as&lt;/P&gt;&lt;P&gt;select one as flag, two, three&lt;/P&gt;&lt;P&gt;from dset&lt;/P&gt;&lt;P&gt;where flag = 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do these statements both yield these same result?&amp;nbsp; If soon, is this documented somewhere.&amp;nbsp; I have found these documentation for using caculated values in a where statements but not for using these column alias in these where statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2011 17:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54464#M15081</guid>
      <dc:creator>kas</dc:creator>
      <dc:date>2011-11-25T17:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54465#M15082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... no different than what happens a data step ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data males;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;set sashelp.class (keep=sex name age rename=(sex=gender));&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;where gender eq 'M';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;create table males as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select sex as gender, name age&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;from sashelp.class&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;where gender eq 'M';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2011 17:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54465#M15082</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-11-25T17:52:15Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54466#M15083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes they will yeild the same result. These alias will further help you when you are using any aggregate functions in your query and ordering your dataset based on that new variable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table yourdata as &lt;/P&gt;&lt;P&gt;select location, sum(salary) as Total_Salary&lt;/P&gt;&lt;P&gt;from employee&lt;/P&gt;&lt;P&gt;group by location&lt;/P&gt;&lt;P&gt;order by Total_Salary Desc;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2011 19:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54466#M15083</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2011-11-25T19:07:40Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54467#M15084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thank you both for you responses; I have a couple of additional questions/comments for anyone who might know the answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps it is not clear, but this does not follow ANSI standards for SQL and so I thought SAS would have this documented.&amp;nbsp; I have not been able to find any yet and this is my question - where is it documented?&amp;nbsp; Someone who has experience writing SQL for Oracle, would find the interchangeability of the alias to original column peculiar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is different than a data step because in your example (for MikeZdeb), you cannot interchange sex/gender in your where statement.&amp;nbsp; The variable has been renamed upon reading and can no longer be referenced by the old value (i.e. sex no longer exists).&amp;nbsp; In my example, either column (source/alias) can be identified in the where clause.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Nov 2011 22:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54467#M15084</guid>
      <dc:creator>kas</dc:creator>
      <dc:date>2011-11-25T22:26:44Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54468#M15085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure what specifically you want to see the documentation for.&amp;nbsp; The two sql statements you originally posted will end up with the same records, but one will have the variable's flag, two and three, and the other will have the variable's one, two and three.&amp;nbsp; The records selected will be the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for other things you might be confused about, you can use dataset options, in SAS, in both SQL and the datastep.&amp;nbsp; If you use them in a datastep, their priority is alphabetical.&amp;nbsp; I.e., drop statements are operated on first, keep second, and rename third.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've never run Oracle SQL, but I would have to think that it would do the same thing in oracle.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Nov 2011 00:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54468#M15085</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-26T00:14:14Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54469#M15086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The SAS documentation for PROC SQL seems to describe this behavior of an alias. "After you assign an alias to a column, you can use the alias to refer to that column in other clauses." &lt;/P&gt;&lt;P&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473678.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473678.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Nov 2011 20:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54469#M15086</guid>
      <dc:creator>Joeldw</dc:creator>
      <dc:date>2011-11-27T20:31:06Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54470#M15087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Again, while I've never used Oracle SQL, the Oracle SQL statement appears to provide conflicting instructions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c_alias Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.&lt;/P&gt;&lt;P&gt;&lt;A href="http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm#SQLRF01702"&gt;http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm#SQLRF01702&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Nov 2011 21:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54470#M15087</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-27T21:01:21Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54471#M15088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Interesting input from everyone. Thanks all for your responses.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;art297 - and I think the Oracle SQL definitions are clearer and that SAS had more conflict in usage.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joeldw - yes, that documentation is helpful but not precise.&amp;nbsp; In practice, after a column is assignged an alias, the alias can be used or the original column name.&amp;nbsp; This is actually pretty cool (but not documented to my knowledge).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data step processing makes sense.&amp;nbsp; The rename executes as the data is read and the original variable name is no longer valid.&amp;nbsp; In SQL, either can be used; I see that as more in conflict than Oracle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyways, I think SAS would better serve its customer base by documenting the 'undocumented features' that we often encounter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Nov 2011 22:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54471#M15088</guid>
      <dc:creator>kas</dc:creator>
      <dc:date>2011-11-27T22:51:48Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54472#M15089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; see &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002294533.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002294533.htm&lt;/A&gt; for doc on the use of "calculated" in SAS sql.&lt;/P&gt;&lt;P&gt;As I understand, the syntax was updated and no longer requires that prefix&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Nov 2011 23:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54472#M15089</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-11-27T23:00:09Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54473#M15090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first few paragraphs below&amp;nbsp; are mostly general comments about column aliasing in the SQL language. The remaining paragraphs are specific to PROC SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effectively, a column alias can be considered to be a temporary renaming of the expression that is being referenced. The duration of this renaming lasts for the lifetime of the query's execution. For example, in the code below, the qty column has been renamed to Quantity and the expression cost+100 has been renamed to ListPrice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title 'columns with aliases';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select qty as Quantity, cost, cost+100 as ListPrice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from calc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The template for an SQL query can be specified, at a high abstraction level, as follows below. The parenthesized numbers at the right of each query part represents its position in the (conceptual) execution order of the parts of an SQL query. More will be said about this below. Please note that planners/optimizers, such as the one that is present in PROC SQL, have the freedom to alter internal execution orders (as long as any alterations do NOT change the meaning of a/the query).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &amp;lt;select list&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (5)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;lt;from clause&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where &amp;lt;where clause&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by &amp;lt;group by clause&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having &amp;lt;having clause&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (4) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by &amp;lt;order by clause&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (6)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Of course, the only mandatory parts of an SQL query are the SELECT and FROM, The other four parts may be optional, depending on what someone is trying to accomplish with the query.&amp;nbsp; Technically, the ORDER BY part is not part of the query. Rather, it is part of a cursor. However, for simplicity, we can pretend that it is part of the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;From the ISO/ANSI SQL Standards perspective, the conceptual order of execution of the six parts, if all are present, is this sequence: the FROM part is executed first, the WHERE part is executed second, the GROUP BY part is executed third, the HAVING part is executed fourth, the SELECT part is executed fifth, and the ORDER BY part is executed last.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ISO/ANSI SQL Standards do not require that the value that is associated with any column alias be present until ORDER BY-time. More specifically, there is no guarantee that a column alias will work as expected if it appears on the clauses that are parts of execution steps 2, 3, and 4, namely, the WHERE clause, GROUP BY clause, and HAVING clause. A column alias is not guaranteed to have been resolved until the beginning of execution step 6 (the start of execution for the ORDER BY part). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The major ramificaton of this is that, per the ISO/ANSI SQL Standards rules regarding column aliases, there is no guarantee, whatsoever, that a SQL processor will resolve a column alias in time for it to be referenced in a &amp;lt;where clause&amp;gt;, &amp;lt;group by clause&amp;gt;, or &amp;lt;having clause&amp;gt;. However, per the Standards, any column alias must be available for reference by the time that the &amp;lt;order by clause&amp;gt; is processed. Hence, for maximum portability of SQL code, it is best to AVOID writing code that refers to column aliases in either a &amp;lt;where clause&amp;gt;, &amp;lt;group by clause&amp;gt;, or &amp;lt;having clause&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In PROC SQL, if a column alias is just a rename of a table column, then either the table name or column name can be used in the &amp;lt;where clause&amp;gt;, &amp;lt;having clause&amp;gt;, or &amp;lt;order by clause&amp;gt;. For example, the first alias in each SELECT part is just a rename of a table column whereas&lt;/P&gt;&lt;P&gt;the second alias refers to a calculated epression. Both the first and second SQL statements below will output the expected results in PROC SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*-- preferred since no column alias is referenced in the &amp;lt;where clause&amp;gt; --*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*-- PORTABLE to other SQL processors --*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select qty as Quantity, cost, cost+100 as ListPrice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from calc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where qty &amp;gt; 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*-- this will work in PROC SQL, but may not work with some other SQL processors --*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select qty as Quantity, cost, cost+100 as ListPrice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from calc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where Quantity &amp;gt; 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;The development of what we know today as PROC SQL began in the 1984-85 timeframe. Some of its scoping and aliasing rules predate those of the first ANSI SQL Standard (1986) and the first ISO SQL Standard (1987). One of the early extensions that was made to PROC SQL was the development of the CALCULATED keyword. Basically, this keyword enables PROC SQL users to reference column aliases that are associated with calculated expressions. The column alias that is being referenced by the CALCULATED keyword can be on either the &amp;lt;where clause&amp;gt;, &amp;lt;group by clause&amp;gt;, &amp;lt;having clause&amp;gt;, or &amp;lt;order by clause&amp;gt;. Make note, though, that the use of the CALCULATED keyword is redundant if is used on the &amp;lt;order by clause&amp;gt; to refer to a column alias because that alias will have been resolved by the time that the execution of the ORDER BY part of a query begins.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, for an example that uses the CALCULATED keyword. Suppose we wish to subset the rows by the value that is associated with the second alias (i.e., ListPrice). Then, it can be accomplished in PROC SQL by this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*-- note the use of the CALCULATED keyword --*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select qty as Quantity, cost, cost+100 as ListPrice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from calc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where CALCULATED ListPrice &amp;gt; 1500;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Unfortunately, the above code is not portable. The ISO/ANSI SQL Standards-approved way of accomplishing this is as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*-- note that the ListPrice column alias does not appear in the &amp;lt;where clause&amp;gt; --*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select qty as Quantity, cost, cost+100 as ListPrice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from calc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where cost+100 &amp;gt; 1500;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that the above comments help to clarify matters somewhat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2011 21:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54473#M15090</guid>
      <dc:creator>LewisC_sas</dc:creator>
      <dc:date>2011-11-30T21:14:00Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54474#M15091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was a good read, thank you Lewis for the insightful post!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2011 21:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54474#M15091</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-11-30T21:37:27Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54475#M15092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that is what I was looking for.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I did not realize proc sql pre-dated the ANSI standards; interesting.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is good information.&amp;nbsp; Is it in the documentation?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Nov 2011 22:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54475#M15092</guid>
      <dc:creator>kas</dc:creator>
      <dc:date>2011-11-30T22:10:42Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54476#M15093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As far as I could determine, this information was not in the current documentation. However, we plan to address this in a future documentation release.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On Tuesday of this week, I talked with the main documentation specialist for PROC SQL about this issue. I am glad to report that from followup correspondence with her during the past two days, the area of the PROC SQL documentation that is relevant to this issue will be modified to reflect the new information that I posted on November 30, 2011 at 4:14 PM. Early this afternoon, the PROC SQL&amp;nbsp; documentation specialist informed me that the revised documentation is not expected to be available to our customers until the latter part of Summer 2012.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2011 19:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54476#M15093</guid>
      <dc:creator>LewisC_sas</dc:creator>
      <dc:date>2011-12-07T19:29:02Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54477#M15094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are welcome. Thanks for your kind comments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2011 19:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54477#M15094</guid>
      <dc:creator>LewisC_sas</dc:creator>
      <dc:date>2011-12-07T19:30:09Z</dc:date>
    </item>
    <item>
      <title>SQL where statement using alias column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54478#M15095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;echoing thanks from others, &lt;/P&gt;&lt;P&gt;it is good to see the documentation update is coming soon ( or very soon - considering the long lifetime of PROC SQL is even greater than ansi sql - half a year seems quick )&lt;/P&gt;&lt;P&gt;peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Dec 2011 09:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-where-statement-using-alias-column/m-p/54478#M15095</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-12-08T09:37:51Z</dc:date>
    </item>
  </channel>
</rss>

