BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasenthusiast07
Fluorite | Level 6

Good evening all,

I have an question in inner join ,

I have performed inner join like this 

proc sql;

create table combine as

select distinct

n.apple,

p.vegges

from 

fruits as n

inner join 

vegetables as p

on 

n.key=p.key;

quit;

 

 

Now in vegges column I have carrots,beans,brocoli,beets--I like my data only to have carrot and beans , how will I apply this condition here.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
The question is, what do you want to happen if that value is not in both tables? What do you want as the output? INNER join only works if it's both tables, if it's one and not the other then you would need to use a LEFT/RIGHT JOIN. Personally, I almost never use an INNER join, I use right/left instead that way if missing values are present they would have missing values and it's an obvious error that's easier to notice. If you use an inner join and accidentally drop a category that's much harder to know.

View solution in original post

3 REPLIES 3
jimbarbour
Meteorite | Level 14

You probably just need a WHERE clause just before the semi-colon.

WHERE vegge IN (carrot, beans)

However, remember that if you're doing an Inner join, only items found in both tables will be present in the results set.  I'm not sure that carrot or beans will be found in an Inner join with fruits.

 

Jim

sasenthusiast07
Fluorite | Level 6

Thanks for the reply.

Appreciate it.

How will I address this issue if not inner join

I have 2 tables A and B

A has Vehicle,Bus,Train

B has Vehicle,road,car

In B table I need only Toyota , camry from car variable 

I can join these tables by vehicle as an common variable 

How should I approach this condition?

Reeza
Super User
The question is, what do you want to happen if that value is not in both tables? What do you want as the output? INNER join only works if it's both tables, if it's one and not the other then you would need to use a LEFT/RIGHT JOIN. Personally, I almost never use an INNER join, I use right/left instead that way if missing values are present they would have missing values and it's an obvious error that's easier to notice. If you use an inner join and accidentally drop a category that's much harder to know.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 557 views
  • 4 likes
  • 3 in conversation