BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

Hi, I have written a code where the address is mentioned in the table header with a # (dr_address##1). When I run the code, it shows an error. Could you please let me know what's wrong in my code? Thanks.

proc sql;
create table Customer_info as
select a.*,
b.dr_title,
b.dr_inits,
b.dr_name,
b.dr_address##1,
b.dr_address##2,
b.dr_address##3,
b.dr_address##4,
b.dr_postcode,
b.dr_phone,
b.dr_phone2,
b.dr_phone3,
b.dr_dob as Date_of_birth,
b.dr_email as email_address,
case when b.dr_phone is not null or 
b.dr_phone2 is not null or 
b.dr_phone3 is not null then 'Y' else 'N'
end as Number_available,
case when Email is not null then 'Y' else 'N'
end as Email_available
from Acc_level_plans as a
inner join p2scflow.debtor as b on a.debt_code=b.debt_code;
quit;

Error log
29         proc sql;
30         create table Customer_info as
31         select a.*,
32         b.dr_title,
33         b.dr_inits,
34         b.dr_name,
35         b.dr_address##1,
                       __
                       22
                       76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, 
              AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, 
              LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

36         b.dr_address##2,
37         b.dr_address##3,
38         b.dr_address##4,
39         b.dr_postcode,
40         b.dr_phone,
41         b.dr_phone2,
42         b.dr_phone3,
43         b.dr_dob as Date_of_birth,
44         b.dr_email as email_address,
2                                                          The SAS System                           09:04 Thursday, December 8, 2022

45         case when b.dr_phone is not null or
46         b.dr_phone2 is not null or
47         b.dr_phone3 is not null then 'Y' else 'N'
48         end as Number_available,
49         case when Email is not null then 'Y' else 'N'
50         end as Email_available
51         from Acc_level_plans as a
52         inner join p2scflow.debtor as b on a.debt_code=b.debt_code;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
53         quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              324.21k
      OS Memory           29528.00k
      Timestamp           12/08/2022 10:57:39 AM
      Step Count                        68  Switch Count  0
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

A SAS variable name can not contain a '#'. You can read about naming conventions of SAS variables in the Rules for Variable Names Documentation

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

A SAS variable name can not contain a '#'. You can read about naming conventions of SAS variables in the Rules for Variable Names Documentation

Sandeep77
Lapis Lazuli | Level 10
Thank you.
D_Dunlap
SAS Employee

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;