<?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: Automatic Variable in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616921#M180705</link>
    <description>&lt;P&gt;Thank's for your reply, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180206"&gt;@JeffMaggio&lt;/a&gt; . As you pointed out, I could use an explicit ALIAS. I could also tell SAS to use the name literal 'User'n, which also works. I am just confused, as to why it is neccessary in PROC SQL and not necessary in other procedures like PROC SORT, for example....&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 14:18:16 GMT</pubDate>
    <dc:creator>FK1</dc:creator>
    <dc:date>2020-01-13T14:18:16Z</dc:date>
    <item>
      <title>Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616909#M180698</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;running this code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_modified;
set sashelp.class;
rename name = User;
run;

proc sql;
create table work.test as select distinct
User 
from work.class_modified;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get as a result from the PROC SQL-Query the "wrong" result (I get my SAS-userid displayed rather than the names of the sashelp.class data set variable "name") becasue the Enterprise Guide parser "thinks" that I want to use the automatic variable "User" rather than the actual variable I renamed.&lt;/P&gt;&lt;P&gt;Alread the syntax highlightning "tells" me this, as it displays the variable in blue rahter than as a black word:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="blue_rather_than_black.JPG" style="width: 394px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35296iAA8E34D219541E99/image-size/medium?v=v2&amp;amp;px=400" role="button" title="blue_rather_than_black.JPG" alt="blue_rather_than_black.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using a different procedure, e.g. PROC SORT, this does not happen (also the highlightning ist correct) :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="proc_sort_user.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35297iCDEA60314C84ABFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="proc_sort_user.JPG" alt="proc_sort_user.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Why does this happen?&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>Mon, 13 Jan 2020 13:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616909#M180698</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2020-01-13T13:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616915#M180703</link>
      <description>&lt;P&gt;The code you posted works fine for me with one minor adjustment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I were you, I would change the variable name as SAS reads the data in (on the set statement), though either way should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_modified;
set sashelp.class (rename=(name = User));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the second step, just explicitly tell SAS to use the User variable from the table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table work.test as select distinct
a.User 
from work.class_modified a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616915#M180703</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-13T14:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616921#M180705</link>
      <description>&lt;P&gt;Thank's for your reply, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180206"&gt;@JeffMaggio&lt;/a&gt; . As you pointed out, I could use an explicit ALIAS. I could also tell SAS to use the name literal 'User'n, which also works. I am just confused, as to why it is neccessary in PROC SQL and not necessary in other procedures like PROC SORT, for example....&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616921#M180705</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2020-01-13T14:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616922#M180706</link>
      <description>&lt;P&gt;USER is a special keyword in PROC SQL.&amp;nbsp; To eliminate the confusion between this special meaning and a reference to a specific variable you can use an alias in your reference to the variable.&amp;nbsp; Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select a.user from mytable a ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616922#M180706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T14:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616923#M180707</link>
      <description>&lt;P&gt;User is a reserved keyword in SQL. The same thing would happen if you have a column named 'from', 'select', etc.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616923#M180707</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-13T14:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616934#M180713</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180206"&gt;@JeffMaggio&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;User is a reserved keyword in SQL. The same thing would happen if you have a column named 'from', 'select', etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is only partly right.&amp;nbsp; USER is not the same type of keyword as FROM or SELECT.&lt;/P&gt;
&lt;P&gt;SAS will happily allow you to use FROM or SELECT as the name of a variable since it can tell from the position in the statement the role the word is playing.&amp;nbsp; But since USER is the name of a metadata variable (the username that is running the query) it is used in the same context as a normal variable name.&amp;nbsp; If you want to reference a variable named USER you just need to add some extra "&lt;A href="https://en.wikipedia.org/wiki/Syntactic_sugar" target="_self"&gt;syntactic sugar&lt;/A&gt;"&amp;nbsp; so that the compiler knows which USER you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select
   user as username
  ,class.user as student_name
  ,select as student_age
  ,from  as student_height
from sashelp.class(obs=2 rename=(name=user height=from age=select))
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 14:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-Variable-in-proc-sql/m-p/616934#M180713</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-13T14:54:23Z</dc:date>
    </item>
  </channel>
</rss>

