Hello All,
By default, the only special character a SAS variable name can include is _ (an underscore). However, you can use special characters like #'s as part of the SAS variable name if you use a SAS name literal (Example: 'dr_address##1'n) and the VALIDVARNAME system option must be set to ANY (options validvarname=any;). This will allow the use of non-standard characters as part of the variable name.
Here is an example using SAS Name literals in a SQL query, since the original question posted included a SQL query. You can also use SAS Name literals to create variables in a DATA step.
You can copy, paste this code and submit it in a SAS environment to see the results:
options validvarname=any;
proc sql; create table nonStandardNames as select make, model, invoice, mpg_city,
'1234 SAS Campus Dr.' as 'dr_address##1'n, 'Cary' as 'dr_address##2'n, 'NC' as 'dr_address##3'n , 27513 as 'dr_address##4'n from sashelp.cars where mpg_city >40;
title "Non-Standard Names"; title2 "Using SAS Name Literals 'dr_address##'n ";
select make, mpg_city, 'dr_address##2'n, 'dr_address##3'n from nonStandardNames; quit;
proc contents data=nonStandardNames; run;
... View more