BookmarkSubscribeRSS Feed
hjkm
Calcite | Level 5
Hi, I'm having troubles with a WHERE clause in a program I am trying to execute. I have multiple conditions I'd like to incorporate but I am getting an error. If anyone has any tips I would appreciate it.

Code is as follows. It's do with the OR statement in that WHERE query, but I'm not sure what I need to correct it. Any help appreciated.

data table1; set work.table;
where ColA="x" and
((Col_date>='01Jan1990'd and ColB="yellow")
or (Col_date>='01Jan1990'd and ColB="blue")) ;
run;

ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, -, /, <, <=,
<>, =, >, >=, AND, EQ, GE, GT, LE, LT, NE, NOT, OR, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored
3 REPLIES 3
hjkm
Calcite | Level 5
Never mind I've managed to sort it out. FYI I had to move 'OR' to the end of the line above where it was previously was.
Doc_Duke
Rhodochrosite | Level 12
Although you fixed it by moving the 'OR', that was probably not the underlying problem. There is a good chance that you had an unprintable character buried in the WHERE clause and, in moving the 'OR' you removed the offending character.

BTW, you could simplify the logic of the WHERE to make it more readable (and probably more efficient) as

where ColA="x" and
Col_date>='01Jan1990'd and
(ColB="yellow" or ColB="blue") ;

Doc Muhlbaier
Duke
LOK
Calcite | Level 5 LOK
Calcite | Level 5
Hi, HJKM


data table;
cola='x';
col_date='01Jan1990'd;
colb='blue';
run;

data table1;
set work.table;
where ColA="x" and
((Col_date >= '01Jan1990'd and ColB = "yellow") or
(Col_date >= '01Jan1990'd and ColB = "blue")) ;

format col_date ddmmyy10.;
proc print;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 2335 views
  • 0 likes
  • 3 in conversation