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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.