Robert Penridge
Robert Penridge

Reputation: 8513

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

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.

Upvotes: 3

Views: 567

Answers (2)

Richard
Richard

Reputation: 27516

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]

Upvotes: 3

Robert Penridge
Robert Penridge

Reputation: 8513

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??

Upvotes: 2

Related Questions