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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1650 views
  • 0 likes
  • 3 in conversation