<?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 - Issues with SQL Reserved words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9371#M487</link>
    <description>I think I left out some key information that may make a difference to the answer for my question.  The data source(s) in question are not SAS datasets, but rather they are database tables accessed via SAS/ACCESS.  The errors are occurring in the translation to the databases language.  Here is the log from simple step I ran, similar to the example provided:&lt;BR /&gt;
&lt;BR /&gt;
27         proc sql;&lt;BR /&gt;
28             create table NEW_TABLE as&lt;BR /&gt;
29             select  Prop_Typ_ID&lt;BR /&gt;
30                     ,PropType.DESC&lt;BR /&gt;
31         	        ,PropType.ORDER&lt;BR /&gt;
32             from    HASP.PROP_TYP as PropType&lt;BR /&gt;
33         ;&lt;BR /&gt;
33       !  quit;&lt;BR /&gt;
ODBC: AUTOCOMMIT is NO for connection 1 5216 1307561914 ducon 0 SQL (2) &lt;BR /&gt;
2                                                          The SAS System                              07:58 Wednesday, June 8, 2011&lt;BR /&gt;
&lt;BR /&gt;
ODBC: AUTOCOMMIT turned ON for connection id 1 5217 1307561914 setconlo 0 SQL (2) &lt;BR /&gt;
  5218 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC_920: Prepared: 5219 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
SELECT * FROM  dbo . PROP_TYP  5220 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5221 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5222 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC_921: Prepared: 5223 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
SELECT   PROP_TYP_ID ,  DESC ,  ORDER   FROM  dbo . PROP_TYP   5224 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5225 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC: ROLLBACK performed on connection 1. 5226 1307561914 du_comm 0 SQL (2) &lt;BR /&gt;
ERROR: CLI describe error: [DataDirect][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'DESC'.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.03 seconds</description>
    <pubDate>Wed, 08 Jun 2011 19:40:27 GMT</pubDate>
    <dc:creator>DerekD_WF</dc:creator>
    <dc:date>2011-06-08T19:40:27Z</dc:date>
    <item>
      <title>PROC SQL - Issues with SQL Reserved words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9369#M485</link>
      <description>I am attempting to write a PROC SQL query, in which a few of the database tables I am querying use reserved words for the column names.  Specifically there are columns name 'ORDER' and 'DESC' in a couple of the tables.  I should also mention that the query has many more selected columns and joined tables than I will show, but here is an example of what a a portion of the query looks like:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table NEW_TABLE as&lt;BR /&gt;
SELECT ,PropType.NUM_OF_UNITS   AS PT_NUM_OF_UNITS&lt;BR /&gt;
              ,PropType.DESC AS PT_DESC&lt;BR /&gt;
              ,PropType.ORDER AS PT_ORDER&lt;BR /&gt;
FROM    Property_Type_lookup as PropType&lt;BR /&gt;
;quit&lt;BR /&gt;
&lt;BR /&gt;
The tables are aliased because there are more than one table that contains the columns 'ORDER' and 'DESC'.  I have tried a couple different methods:&lt;BR /&gt;
&lt;BR /&gt;
1.  using the DQUOTE=ANSI option and typing the selected variable as both ,"PropType.ORDER" and ,Proptype."ORDER".  I wasn't able to get that to work.&lt;BR /&gt;
&lt;BR /&gt;
2.  Setting VALIDVARNAME = ANY and using name literals:  'PropType.ORDER'n&lt;BR /&gt;
&lt;BR /&gt;
3.  Using (rename=(ORDER=PT_ORDER))  options on the datasets that use reserved in "FROM" portion of the query.&lt;BR /&gt;
&lt;BR /&gt;
My questions are the following:  Does the DQUOTE= option work with aliased table references and if so how where do you place the double quotes to get SAS to correctly read the column from the database?  &lt;BR /&gt;
&lt;BR /&gt;
Any insight or other options as to how I can make this work would be appreciated.</description>
      <pubDate>Wed, 08 Jun 2011 15:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9369#M485</guid>
      <dc:creator>DerekD_WF</dc:creator>
      <dc:date>2011-06-08T15:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL - Issues with SQL Reserved words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9370#M486</link>
      <description>Derek,&lt;BR /&gt;
&lt;BR /&gt;
Once I removed the typo from your SELECT statement (leading comma), your code ran fine, so the problem is not where you are showing us.&lt;BR /&gt;
&lt;BR /&gt;
Perhaps you can simplify your program, get that to fail, and include the log.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke&lt;BR /&gt;
-----------------&lt;BR /&gt;
&lt;BR /&gt;
DATA Property_type_lookup;&lt;BR /&gt;
input num_of_units desc order;&lt;BR /&gt;
cards;&lt;BR /&gt;
3 4 5&lt;BR /&gt;
6 7 8&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table NEW_TABLE as&lt;BR /&gt;
SELECT PropType.NUM_OF_UNITS AS PT_NUM_OF_UNITS&lt;BR /&gt;
,PropType.DESC AS PT_DESC&lt;BR /&gt;
,PropType.ORDER AS PT_ORDER&lt;BR /&gt;
FROM Property_Type_lookup as PropType&lt;BR /&gt;
;quit</description>
      <pubDate>Wed, 08 Jun 2011 18:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9370#M486</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2011-06-08T18:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL - Issues with SQL Reserved words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9371#M487</link>
      <description>I think I left out some key information that may make a difference to the answer for my question.  The data source(s) in question are not SAS datasets, but rather they are database tables accessed via SAS/ACCESS.  The errors are occurring in the translation to the databases language.  Here is the log from simple step I ran, similar to the example provided:&lt;BR /&gt;
&lt;BR /&gt;
27         proc sql;&lt;BR /&gt;
28             create table NEW_TABLE as&lt;BR /&gt;
29             select  Prop_Typ_ID&lt;BR /&gt;
30                     ,PropType.DESC&lt;BR /&gt;
31         	        ,PropType.ORDER&lt;BR /&gt;
32             from    HASP.PROP_TYP as PropType&lt;BR /&gt;
33         ;&lt;BR /&gt;
33       !  quit;&lt;BR /&gt;
ODBC: AUTOCOMMIT is NO for connection 1 5216 1307561914 ducon 0 SQL (2) &lt;BR /&gt;
2                                                          The SAS System                              07:58 Wednesday, June 8, 2011&lt;BR /&gt;
&lt;BR /&gt;
ODBC: AUTOCOMMIT turned ON for connection id 1 5217 1307561914 setconlo 0 SQL (2) &lt;BR /&gt;
  5218 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC_920: Prepared: 5219 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
SELECT * FROM  dbo . PROP_TYP  5220 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5221 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5222 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC_921: Prepared: 5223 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
SELECT   PROP_TYP_ID ,  DESC ,  ORDER   FROM  dbo . PROP_TYP   5224 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
  5225 1307561914 du_prep 0 SQL (2) &lt;BR /&gt;
ODBC: ROLLBACK performed on connection 1. 5226 1307561914 du_comm 0 SQL (2) &lt;BR /&gt;
ERROR: CLI describe error: [DataDirect][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'DESC'.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.03 seconds</description>
      <pubDate>Wed, 08 Jun 2011 19:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9371#M487</guid>
      <dc:creator>DerekD_WF</dc:creator>
      <dc:date>2011-06-08T19:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL - Issues with SQL Reserved words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9372#M488</link>
      <description>Since the SQL/Server allowed the column names, you may be able to use explicit pass-thru code to do the work on the server end and just get the renamed results back.&lt;BR /&gt;
&lt;BR /&gt;
This is a kluge, but you might be able to use PROC COPY to copy the tables into SAS datasets on WORK and then do your SQL on SAS datasets.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke</description>
      <pubDate>Wed, 08 Jun 2011 23:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9372#M488</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2011-06-08T23:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL - Issues with SQL Reserved words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9373#M489</link>
      <description>Thanks for the suggestion.  I did something similar to this.  Since the tables in my joins that are impacted by the reserved words are very small lookup tables, I just did separate data steps to create temporary datasets in the Work library and used a rename= option to change the variable names.</description>
      <pubDate>Thu, 09 Jun 2011 15:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Issues-with-SQL-Reserved-words/m-p/9373#M489</guid>
      <dc:creator>DerekD_WF</dc:creator>
      <dc:date>2011-06-09T15:01:51Z</dc:date>
    </item>
  </channel>
</rss>

