BookmarkSubscribeRSS Feed
Citrine10
Obsidian | Level 7

hi there

 

i get the below error when trying to run my code

Error 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, THEN, ^, ^=, |
Syntax error, statement will be ignored

code:

proc sql;

select reference,

case when age >= 0 and age<= 10 then '0-10'

when age>=11 and age<=20 then '11-20'

end as AgeBucket

;quit;

 

7 REPLIES 7
Reeza
Super User
You have no FROM statement so that isn't a valid SAS query. Did you forget to specify your input data set?
Citrine10
Obsidian | Level 7
Sorry Reeza i do have a from i just forgot to add it while typing this out as i couldnt copy, paste across different VM's
Reeza
Super User
Well, we need your full query and log to be able to tell you what could be wrong.
SAS usually underlines the issue or specifies the location (Line/Column number) that make it fairly easily to find the issue if you're familiar with reading the error messages. This means your syntax isn't correct somewhere in your code.
Citrine10
Obsidian | Level 7
it seems to be giving an error when doing multiple 'when's' in the case statement eg running
code:

proc sql;
select reference,
case when age >= 0 and age<= 10 then '0-10'
when age>=11 and age<=20 then '11-20'
end as AgeBucket
from table1
;quit;

but works when running:

proc sql;
select reference,
case when age >= 0 and age<= 10 then '0-10'
else ''
end as AgeBucket
from table1
;quit;
Tom
Super User Tom
Super User

Both queries look fine. Make sure you don't have spurious characters, like an extra comma or semi-colon.  Missing spaces between the tokens so that your string literals look like other types of literals.  'xxx't is a TIME literal. Or just plain invalid characters, like TAB, CR, LF or non-breaking spaces , that might not show anything on the screen.

 

Your second one is more likely to cause errors because you have two quotes right next to each other.  Put a space between them to make sure it looks like a string literal instead of just a doubled up embedded quote in the middle of some longer string literal.

Kurt_Bremser
Super User

Copy/paste (!!) the whole log, beginning with the PROC SQL statement and ending with the final NOTE about the SQL runtime into a box opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

Do not do anything else with the log text.

ballardw
Super User

Copy the code and all the notes, messages or warnings along with the error messages. Paste all of that into a code box opened with the </>.

 

It is amazing how many times "code" shown does not actually turn  out to be what was actually submitted. Copying the code with the messages for log confirms exactly what was submitted.

Typically a 22-322 error includes diagnostic characters indicating exactly where SAS determined the error occurred. So you only copied part of the error message and left out all the bits that were telling you where the actual error or was found.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1162 views
  • 2 likes
  • 5 in conversation