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-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!

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.

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