Help using Base SAS procedures

Help with WHERE clause

New Contributor
Posts: 2

Help with WHERE clause

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")) ;

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
New Contributor
Posts: 2

Re: Help with WHERE clause

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.
Trusted Advisor
Posts: 2,125

Re: Help with WHERE clause

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
Occasional Contributor LOK
Occasional Contributor
Posts: 11

Re: Help with WHERE clause


data table;

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;
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation