<?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: Syntax error in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856511#M37801</link>
    <description>&lt;P&gt;It doesn't like the value of your macro variable &amp;amp;PC_variable. What is the value of this macro variable before you run PROC SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;40         		sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
                                                                                                                             _
                                                                                                                             22
                                                                                                                             200
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, 
              GT, GTT, LE, LET, LT, LTT, NE, NET, NOT, OR, THEN, ^, ^=, |, ||, ~, ~=.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is complaining about mismatched parenthesis earlier than your&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;left join (select *from connection to oledb
(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns]))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;41         				then 1 else 0
42         			end as Returned_mail
                  __
                  79

ERROR 79-322: Expecting a ).&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2023 18:59:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-01-31T18:59:43Z</dc:date>
    <item>
      <title>Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856497#M37796</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am running a code which I think is correct but I am getting syntax error and I am unable to spot what is wrong with the code. Can you please check the code and log and help me to spot the error please? Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	connect to oledb (provider=sqlncli11.1
		properties = ("Integrated Security" = SSPI
		"Persist Security Info" = False
		"Initial Catalog" = dbLetters
		prompt = NO
		"Data Source" = 'ORPHEUS'
		read_lock_type = no));
create table Returned_Mail as 
	select distinct
				a.*
				sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
				then 1 else 0 
			end as Returned_mail
		from Complaints as a 
			left join (select *from connection to oledb 
				(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns])) as b on a.AccountNumber =b.debtcode  
					group by a.AccountNumber;
quit; 


Error log:


29         proc sql;
30         	connect to oledb (provider=sqlncli11.1
31         		properties = ("Integrated Security" = SSPI
32         		"Persist Security Info" = False
33         		"Initial Catalog" = dbLetters
34         		prompt = XX
35         		"Data Source" = 'ORPHEUS'
36         		read_lock_type = no));

37         create table Returned_Mail as
38         	select distinct
39         				a.*
40         				sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
               ___
               22
               76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

41         				then 1 else 0
42         			end as Returned_mail
43         		from Complaints as a
44         			left join (select *from connection to oledb
2                                                          The SAS System                            14:02 Tuesday, January 31, 2023

45         				(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns])) as b on a.AccountNumber =b.debtcode
46         					group by a.AccountNumber;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
47         quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 17:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856497#M37796</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-01-31T17:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856502#M37797</link>
      <description>At minimum the last select is missing a closing parenthesis, but doubt that's the full issue. Have you tested the inner query works before that distinct query?</description>
      <pubDate>Tue, 31 Jan 2023 17:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856502#M37797</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-31T17:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856503#M37798</link>
      <description>&lt;PRE&gt;39         				a.*
40         				sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
&lt;/PRE&gt;
&lt;P&gt;There should be a comma after a.*&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 17:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856503#M37798</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-31T17:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856508#M37799</link>
      <description>&lt;P&gt;Hi, but the last select does have a parenthesis&lt;BR /&gt;left join&lt;FONT color="#FF00FF"&gt; (&lt;/FONT&gt;select *from connection to oledb &lt;BR /&gt;&lt;FONT color="#FF6600"&gt;(&lt;/FONT&gt;select * from [dbLetters].[dbo].[tReturnedMailDailyReturns]&lt;FONT color="#FF6600"&gt;)&lt;/FONT&gt;&lt;FONT color="#FF00FF"&gt;)&lt;/FONT&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 17:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856508#M37799</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-01-31T17:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856509#M37800</link>
      <description>&lt;P&gt;I added the comma after a.* but still getting the error. Please see the updated code and error log below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	connect to oledb (provider=sqlncli11.1
		properties = ("Integrated Security" = SSPI
		"Persist Security Info" = False
		"Initial Catalog" = dbLetters
		prompt = NO
		"Data Source" = 'ORPHEUS'
		read_lock_type = no));
create table Returned_Mail as 
	select distinct
				a.*,
				sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
				then 1 else 0 
			end as Returned_mail
		from Complaints as a 
			left join (select *from connection to oledb 
				(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns])) as b on a.AccountNumber =b.debtcode  
					group by a.AccountNumber;
quit; 

Error log:
29         proc sql;
30         	connect to oledb (provider=sqlncli11.1
31         		properties = ("Integrated Security" = SSPI
32         		"Persist Security Info" = False
33         		"Initial Catalog" = dbLetters
34         		prompt = XX
35         		"Data Source" = 'ORPHEUS'
36         		read_lock_type = no));

37         create table Returned_Mail as
38         	select distinct
39         				a.*,
40         				sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
                                                                                                                             _
                                                                                                                             22
                                                                                                                             200
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, 
              GT, GTT, LE, LET, LT, LTT, NE, NET, NOT, OR, THEN, ^, ^=, |, ||, ~, ~=.  

ERROR 200-322: The symbol is not recognized and will be ignored.

41         				then 1 else 0
42         			end as Returned_mail
                  __
                  79
2                                                          The SAS System                            14:02 Tuesday, January 31, 2023

ERROR 79-322: Expecting a ).

43         		from Complaints as a
44         			left join (select *from connection to oledb
45         				(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns])) as b on a.AccountNumber =b.debtcode
                ______
                79
                76
ERROR 79-322: Expecting a ).

ERROR 76-322: Syntax error, statement will be ignored.

46         					group by a.AccountNumber;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
47         quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 17:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856509#M37800</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-01-31T17:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856511#M37801</link>
      <description>&lt;P&gt;It doesn't like the value of your macro variable &amp;amp;PC_variable. What is the value of this macro variable before you run PROC SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;40         		sum(Case when not missing (a.&amp;amp;PC_variable) and compress(upcase(b.Postcode)) = compress(upcase(a.&amp;amp;PC_variable)))
                                                                                                                             _
                                                                                                                             22
                                                                                                                             200
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, 
              GT, GTT, LE, LET, LT, LTT, NE, NET, NOT, OR, THEN, ^, ^=, |, ||, ~, ~=.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is complaining about mismatched parenthesis earlier than your&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;left join (select *from connection to oledb
(select * from [dbLetters].[dbo].[tReturnedMailDailyReturns]))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;41         				then 1 else 0
42         			end as Returned_mail
                  __
                  79

ERROR 79-322: Expecting a ).&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 18:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856511#M37801</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-31T18:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856515#M37802</link>
      <description>The parenthesis is too early on the CASE statement. &lt;BR /&gt;</description>
      <pubDate>Tue, 31 Jan 2023 18:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856515#M37802</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-31T18:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856538#M37803</link>
      <description>The value of macro variable is&lt;BR /&gt;%let PC_variable = tcfPostCode ; &lt;BR /&gt;TCFpostcode is basically the post code.</description>
      <pubDate>Tue, 31 Jan 2023 20:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856538#M37803</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-01-31T20:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856539#M37804</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The value of macro variable is&lt;BR /&gt;%let PC_variable = tcfPostCode ; &lt;BR /&gt;TCFpostcode is basically the post code.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the context of this problem, it really doesn't matter what the variable means ... let me ask you this ... is tcfpostcode the name of a variable in data set Complaints?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, just before PROC SQL, run this command and report the results which should get written to the log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=pc_variable;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 22:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856539#M37804</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-31T22:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856540#M37805</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few obvious but mainly cosmetic things to check/fix.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It is impossible to read when the lines are so long. Avoid code lines longer than 70-80 bytes.&lt;/LI&gt;
&lt;LI&gt;Do you really want the DISTINCT keyword?&amp;nbsp; Why?&lt;/LI&gt;
&lt;LI&gt;Do you really want to use A.* with GROUP BY ?&amp;nbsp; SAS will have to REMERGE the aggregate values onto the detail observations.&lt;/LI&gt;
&lt;LI&gt;The "AS" keyword before the table references feels wrong.&amp;nbsp; SAS might accept it (and some strange SQL dialects might require it) but it still feels wrong.&lt;/LI&gt;
&lt;LI&gt;Do not have a space between a function name (missing) and the () around the argument list.&lt;/LI&gt;
&lt;LI&gt;Place ending semicolon for a multiple line statement on a NEW line where it is visible to humans.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;But the real issue is probably your parentheses placements.&lt;/P&gt;
&lt;P&gt;1) Add () around the WHEN condition.&lt;/P&gt;
&lt;P&gt;2) CLOSE the () for the SUM() aggregate function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formatting will help with making it easier to check the () placements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table Returned_Mail as 
select distinct
  a.*
 ,sum(
   case when (not missing(a.&amp;amp;PC_variable)
              and compress(upcase(b.Postcode))=compress(upcase(a.&amp;amp;PC_variable))
             )
        then 1 else 0 
   end
   ) as Returned_mail
from Complaints a 
left join 
 (select * from connection to oledb 
   (select * from [dbLetters].[dbo].[tReturnedMailDailyReturns])
 ) b
on a.AccountNumber=b.debtcode  
group by a.AccountNumber
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 21:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856540#M37805</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-31T21:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856542#M37806</link>
      <description>&lt;P&gt;The log should show the contents of the macro variable if it was resolved successfully, not its name.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 21:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Syntax-error/m-p/856542#M37806</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-31T21:14:17Z</dc:date>
    </item>
  </channel>
</rss>

