<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can the SAS code include a #? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848510#M37044</link>
    <description>&lt;P&gt;A SAS variable name can not contain a '#'. You can read about naming conventions of SAS variables in the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm" target="_self"&gt;Rules for Variable Names Documentation&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2022 11:06:28 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-12-08T11:06:28Z</dc:date>
    <item>
      <title>Can the SAS code include a #?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848509#M37043</link>
      <description>&lt;P&gt;Hi, I have written a code where the address is mentioned in the table header with a # (&lt;CODE class=" language-sas"&gt;dr_address##1)&lt;/CODE&gt;. When I run the code, it shows an error. Could you please let me know what's wrong in my code? Thanks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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, !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, 
              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&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Dec 2022 11:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848509#M37043</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-12-08T11:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can the SAS code include a #?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848510#M37044</link>
      <description>&lt;P&gt;A SAS variable name can not contain a '#'. You can read about naming conventions of SAS variables in the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm" target="_self"&gt;Rules for Variable Names Documentation&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 11:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848510#M37044</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-12-08T11:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can the SAS code include a #?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848511#M37045</link>
      <description>Thank you.</description>
      <pubDate>Thu, 08 Dec 2022 11:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848511#M37045</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-12-08T11:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can the SAS code include a #?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848521#M37050</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;By &lt;EM&gt;default&lt;/EM&gt;, the only special character a SAS variable name can include is _ (an underscore). &lt;STRONG&gt;&lt;EM&gt;However,&lt;/EM&gt;&lt;/STRONG&gt; you can use special characters like #'s as part of the SAS variable name if you use a &lt;A title="SAS Name Literal" href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p0z9rbr2w2vtd1n1q8lty9b13iv3.htm" target="_blank" rel="noopener"&gt;SAS name literal&lt;/A&gt; (&lt;STRONG&gt;Example&lt;/STRONG&gt;: &lt;FONT face="courier new,courier"&gt;'dr_address##1'n&lt;/FONT&gt;) and the VALIDVARNAME system option must be set to ANY (&lt;FONT face="courier new,courier"&gt;options validvarname=any;&lt;/FONT&gt;). This will allow the use of non-standard characters as part of the variable name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can copy, paste this code and submit it in a SAS environment to see the results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;options validvarname=any;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;create table nonStandardNames as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;select make, model, invoice, mpg_city, &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'1234 SAS Campus Dr.' as &lt;STRONG&gt;'dr_address##1'n&lt;/STRONG&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Cary' as &lt;STRONG&gt;'dr_address##2'n&lt;/STRONG&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'NC' as &lt;STRONG&gt;'dr_address##3'n&amp;nbsp;&lt;/STRONG&gt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;27513 as &lt;STRONG&gt;'dr_address##4'n&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;from sashelp.cars&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;where mpg_city &amp;gt;40;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;title "Non-Standard Names";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;title2 "Using SAS Name Literals 'dr_address##'n ";&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp;select make, mpg_city, &lt;STRONG&gt;'dr_address##2'n&lt;/STRONG&gt;, &lt;STRONG&gt;'dr_address##3'n &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; from nonStandardNames;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc contents data=nonStandardNames;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2022 11:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-the-SAS-code-include-a/m-p/848521#M37050</guid>
      <dc:creator>D_Dunlap</dc:creator>
      <dc:date>2022-12-08T11:52:00Z</dc:date>
    </item>
  </channel>
</rss>

