This caused some unexpected pain: one cannot use the variable USER in SQL:
data one ;
user = 1 ;
run ;
proc sql ;
select user
from one
;
quit ;
proc sql ;
select "user"n
from one
;
quit ;
ƒƒƒƒƒƒ
kv1906
user
ƒƒƒƒƒƒƒƒ
1
I did not see that coming and it was suprising given how many data sets must have variable USER.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M1)
NOTE: This session is executing on the X64_S08R2 platform.
NOTE: Additional host information:
X64_S08R2 WIN 6.1.7601 Service Pack 1 Server
Enjoy,
Kevin
Documented under SQL reserved words:
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. 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.
Try this program
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.