Problems with reserved field name 'user' in SAS Proc SQL

Viewed 240

How do I select the user column from my table and not select the surprise 'feature' SAS added to their SQL syntax:

data have;
 user = 'huh??';
run;

proc sql ;
  select user from have;
quit;

Result:

rob

Bonus, the field name in the result table (if you create one) gets a temporary name... ie. something like _TEM001.

2 Answers

Use the name literal syntax, '<name>'n

select 'user'n from have;

Name literals in other systems, such as in pass through:

  • Oracle - double quoted. "user"
  • SQL Server - square bracketed [user]

You can use column literals to refer specifically to the field name rather than the reserved keyword:

proc sql ;
  select 'user'n from have;
quit;

Result:

huh??
Related