<?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: SQL: User as a variable / BUG in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367810#M87622</link>
    <description>&lt;P&gt;You will see that for a few special keywords that ANSI SQL defines and SAS supports. You will have similar problems in other implementations of SQL. The easiest fix is to add the alias to the variable name reference.&amp;nbsp;In addition to using the name literal approach you can add the DQUOTE=ANSI option to PROC SQL and then it will treat values in double quotes as meaning the name of field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this program&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql dquote=ansi ;
  select user 'Bare user'
       , "user" 'DQUOTED user'
       , 'user'n 'NLITERAL user'
       , a.user 'Alias included'
       , *
  from sashelp.class(obs=1 rename=(name=user)) a
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2017 17:15:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-06-16T17:15:40Z</dc:date>
    <item>
      <title>SQL: User as a variable / BUG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367803#M87618</link>
      <description>&lt;P&gt;This caused some unexpected pain: one cannot use the variable USER in SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="4"&gt; one ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT size="4"&gt;&amp;nbsp;&amp;nbsp; user = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="4"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" size="4"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000ff" size="4"&gt;&amp;nbsp; select&lt;/FONT&gt; &lt;FONT color="#0000ff" size="4"&gt;user&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000ff" size="4"&gt;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT size="4"&gt; one&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" size="4"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000ff" size="4"&gt;&amp;nbsp; select&lt;/FONT&gt; &lt;FONT color="#800080" size="4"&gt;"user"n&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000ff" size="4"&gt;&amp;nbsp; from&lt;/FONT&gt;&lt;FONT size="4"&gt; one&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#000080" size="4"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="4"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ƒƒƒƒƒƒ&lt;/P&gt;
&lt;P&gt;kv1906&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;user&lt;/P&gt;
&lt;P&gt;ƒƒƒƒƒƒƒƒ&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT size="4"&gt;I did not see that coming and it was suprising given how many data sets must have variable USER.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: SAS (r) Proprietary Software 9.4 (TS1M1)&lt;/P&gt;
&lt;P&gt;NOTE: This session is executing on the X64_S08R2 platform.&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;NOTE: Additional host information:&lt;/P&gt;
&lt;P&gt;X64_S08R2 WIN 6.1.7601 Service Pack 1 Server&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enjoy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 16:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367803#M87618</guid>
      <dc:creator>KevinViel</dc:creator>
      <dc:date>2017-06-16T16:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: SQL: User as a variable / BUG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367809#M87621</link>
      <description>&lt;P&gt;Documented under SQL reserved words:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p0dwck5j6adm6tn1ftsifs3mxwcl"&gt;The keyword USER is reserved for the current user ID. If you specify USER in a SELECT statement in conjunction with a CREATE TABLE statement, then the column is created in the table with a temporary column name that is similar to _TEMA001. If you specify USER in a SELECT statement without a CREATE TABLE statement, then the column is written to the output without a column heading. In either case, the value for the column varies by operating environment, but is typically the user ID of the user who is submitting the program or the value of the &amp;amp;SYSJOBID automatic macro variable.&lt;/DIV&gt;</description>
      <pubDate>Fri, 16 Jun 2017 17:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367809#M87621</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-16T17:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: SQL: User as a variable / BUG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367810#M87622</link>
      <description>&lt;P&gt;You will see that for a few special keywords that ANSI SQL defines and SAS supports. You will have similar problems in other implementations of SQL. The easiest fix is to add the alias to the variable name reference.&amp;nbsp;In addition to using the name literal approach you can add the DQUOTE=ANSI option to PROC SQL and then it will treat values in double quotes as meaning the name of field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this program&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql dquote=ansi ;
  select user 'Bare user'
       , "user" 'DQUOTED user'
       , 'user'n 'NLITERAL user'
       , a.user 'Alias included'
       , *
  from sashelp.class(obs=1 rename=(name=user)) a
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 17:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-User-as-a-variable-BUG/m-p/367810#M87622</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-16T17:15:40Z</dc:date>
    </item>
  </channel>
</rss>

