BookmarkSubscribeRSS Feed
Simo
Calcite | Level 5
Hi,
I need to match cases from 2 datasets in a way that they match in region, ID, diagnose code and date.

region, ID and diagnose are exact matches but date can be a match from 3 different date variables in database 2.

Here's the syntax

PROC SQL;
CREATE TABLE d1d2
AS
SELECT*
FROM d1,d2
WHERE d1.region=d2.region2 and d1.ID=d2.ID2 and d1.diagnose=d2.diagnose and
d1.date=d2.date1 OR
d1.date=d2.date2 OR
d1.date=d2.date3 OR
;
QUIT;

Works fine until the OR so what how to get it to work?


S
3 REPLIES 3
Flip
Fluorite | Level 6
At first glance, you have an extra 'OR'. I would also throw in some parentheses to control presedence.

WHERE d1.region=d2.region2 and d1.ID=d2.ID2 and d1.diagnose=d2.diagnose and
(d1.date=d2.date1 OR
d1.date=d2.date2 OR
d1.date=d2.date3 )
;
Simo
Calcite | Level 5
Thanks a lot, seems to work now. Needed the brackets.

S
Peter_C
Rhodochrosite | Level 12
the brackets were not enough ~~ you also needed to lose the last (trailing) OR.

technically speaking, OR is an INFIX operator
It needs something after the OR as well as before it.

PeterC

sas-innovate-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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