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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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