<?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: Column Name Matches SAS' FEDSQL Reserve Words in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935391#M42035</link>
    <description>Thank you Tom, this worked!</description>
    <pubDate>Wed, 10 Jul 2024 19:12:06 GMT</pubDate>
    <dc:creator>ljim1075</dc:creator>
    <dc:date>2024-07-10T19:12:06Z</dc:date>
    <item>
      <title>Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935231#M42020</link>
      <description>&lt;P&gt;Hello everyone!&amp;nbsp; I'm counting total number of distinct values from all columns from various tables.&amp;nbsp; What I've come across is that some of the column name matches that of SAS' Reserve Words.&amp;nbsp; So the questions is simple, how can I query based on these words; i.e. add, tran, user, etc.&amp;nbsp; Sample of error msg is:&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near the keyword&lt;/DIV&gt;&lt;DIV class=""&gt;'ADD'.&lt;/DIV&gt;&lt;DIV class=""&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE Dist_Val_ADD AS&lt;BR /&gt;SELECT&lt;BR /&gt;"ADD" AS Column_Name,&lt;BR /&gt;COUNT(DISTINCT ADD) as Num_Dist_Values FORMAT COMMA10.&lt;BR /&gt;FROM CONN.&amp;amp;TBLNM.&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I've also tried:&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;COUNT(DISTINCT CATS("A.",ADD)) as Num_Dist_Values FORMAT COMMA10.&lt;/LI&gt;&lt;LI&gt;COUNT(DISTINCT CATS("[",ADD.,"]")) as Num_Dist_Values FORMAT COMMA10.&lt;/LI&gt;&lt;LI&gt;COUNT(DISTINCT CATS("'",ADD,"'N")) as Num_Dist_Values FORMAT COMMA10.&lt;/LI&gt;&lt;LI&gt;COUNT(DISTINCT CATS("'",ADD,"'")) as Num_Dist_Values FORMAT COMMA10.&lt;/LI&gt;&lt;LI&gt;COUNT(DISTINCT CATS('"',ADD,'"')) as Num_Dist_Values FORMAT COMMA10.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;All have failed and resulted in the same error msg.&amp;nbsp; The table is in SQL Server, but may have other table in other platforms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other suggestions???&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 20:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935231#M42020</guid>
      <dc:creator>ljim1075</dc:creator>
      <dc:date>2024-07-09T20:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935244#M42021</link>
      <description>Rename it before referring to it ?&lt;BR /&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE Dist_Val_ADD AS&lt;BR /&gt;SELECT&lt;BR /&gt;_ADD ,&lt;BR /&gt;COUNT(DISTINCT _ADD) as Num_Dist_Values FORMAT=COMMA10.&lt;BR /&gt;FROM CONN.&amp;amp;TBLNM.(rename=(ADD=_ADD))&lt;BR /&gt;;&lt;BR /&gt;QUIT;</description>
      <pubDate>Wed, 10 Jul 2024 01:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935244#M42021</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-07-10T01:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935283#M42025</link>
      <description>&lt;P&gt;The ERROR does not come from SAS. It originates in the MS SQL server, so it seems someone managed to create an illegal column name there. Or the column isn't even there in the first place; you may have mistaken a label for a name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS run PROC CONTENTS on&amp;nbsp;&lt;SPAN&gt;CONN.&amp;amp;TBLNM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 08:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935283#M42025</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-07-10T08:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935304#M42030</link>
      <description>&lt;P&gt;Thank you Ksharp for your suggestion, I know that _ADD will work, the issue lies that this is running in a un-monitored DO LOOP and the code will have failures that I would have to manually update one by one.&amp;nbsp; I want to automate as much as possible.&amp;nbsp; My thought if there's a SAS backend table with the list of reserve words then I can make a comparison and replace those that matches the reserve words.&amp;nbsp; Hopes this makes sense...&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 12:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935304#M42030</guid>
      <dc:creator>ljim1075</dc:creator>
      <dc:date>2024-07-10T12:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935308#M42031</link>
      <description>&lt;P&gt;Kurt, the field is in the table, notice the fields Tran and Add in this particular table&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ljim1075_1-1720613337615.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98287iFF73904A9866E212/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ljim1075_1-1720613337615.png" alt="ljim1075_1-1720613337615.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ljim1075_2-1720613352234.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98288iECC5F1029CAA5C69/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ljim1075_2-1720613352234.png" alt="ljim1075_2-1720613352234.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 12:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935308#M42031</guid>
      <dc:creator>ljim1075</dc:creator>
      <dc:date>2024-07-10T12:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935318#M42032</link>
      <description>&lt;P&gt;Not sure why you mentioned PROC FEDSQL since you don't seem to be using it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normal PROC SQL has an option to treat strings in double quotes as variable names.&amp;nbsp; So any actual string literals have to use single quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL dquote=ansi;
CREATE TABLE Dist_Val_ADD AS
SELECT
   'ADD' AS Column_Name
 , COUNT(DISTINCT "ADD") as Num_Dist_Values FORMAT COMMA10.
FROM CONN.&amp;amp;TBLNM.
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2024 13:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935318#M42032</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-10T13:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935354#M42033</link>
      <description>Tom, in general what I'm trying to do is to inquiry on a column name that matches SAS overall reserve words, for example, user, date, add, etc. My issue is primarily on the COUNT(DISTINCT "ADD") as Num_Dist_Values FORMAT COMMA10. I've added the bquote option and that didn't work either</description>
      <pubDate>Wed, 10 Jul 2024 15:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935354#M42033</guid>
      <dc:creator>ljim1075</dc:creator>
      <dc:date>2024-07-10T15:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935373#M42034</link>
      <description>&lt;P&gt;It is NOT a problem for SAS.&amp;nbsp; Try it with an actual SAS dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data add;
  input add ;
cards;
1
2
3
;

proc sql;
 select count(distinct add) as n_add 
 from add
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So your problem is related to how SAS is converting the code into SQL it can run in the foreign database that the libref your original code was using was pointing into.&lt;/P&gt;
&lt;P&gt;I would look into seeing if there are libname options you can use to force SAS to use syntax to make valid variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really cannot find a solution to make SAS automatically make valid syntax you will have to resort to writing your own SQL that works in that database.&amp;nbsp; I think your previous error message seemed to indicate that it is Microsoft SQL Server.&amp;nbsp; In that case I think they use [] around names.&amp;nbsp; So perhaps you could get the job done by running code like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mylib .... ;
proc sql;
connect using mylib;
create table want as
select 'ADD' as varname, Num_Dist_Values format=comma10.
from connection to mylib(
  select COUNT(DISTINCT [ADD]) as Num_Dist_Values 
  from mysql_table_name
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2024 17:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935373#M42034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-10T17:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Column Name Matches SAS' FEDSQL Reserve Words</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935391#M42035</link>
      <description>Thank you Tom, this worked!</description>
      <pubDate>Wed, 10 Jul 2024 19:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Column-Name-Matches-SAS-FEDSQL-Reserve-Words/m-p/935391#M42035</guid>
      <dc:creator>ljim1075</dc:creator>
      <dc:date>2024-07-10T19:12:06Z</dc:date>
    </item>
  </channel>
</rss>

