DATA Step, Macro, Functions and more

Why left join doesn't bring everything from left

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Why left join doesn't bring everything from left

Hi

I have 2 tables table a and table b
I want everything coming from table a An only where we match table b.

From table. A left join table b on a.tid =b.tid and a.date = b.date



Table a has 7500 records table b has 100k records when I run it i get 7200 records ... I don't know why it's dropping 300 records ....thanks

Accepted Solutions
Solution
‎03-02-2017 01:09 AM
Super User
Super User
Posts: 6,499

Re: Why left join doesn't bring everything from left

You are getting MORE records than exist in the source table A, not LESS.

This happens when there are mulitple records in B for some of the key variables. So in this case there are some values of ID and DATE that have more than one record in table B and also appear in table A.

View solution in original post


All Replies
Super User
Super User
Posts: 6,499

Re: Why left join doesn't bring everything from left

You most have a WHERE or a GROUP BY or some other way that is subsetting the results.

Without seeing the full query and the SAS log it is hard to diagnosis further.

Respected Advisor
Posts: 3,889

Re: Why left join doesn't bring everything from left

Is there anything else in your SQL that could cause this drop of records (i.e. a DISTINCT in the SELECT clause)?

 

Please post your SQL code and the related log.

Contributor
Posts: 65

Re: Why left join doesn't bring everything from left

From table a left join table b on b.date = a.date And b.id =a.id
And b.tracking is not null
), run;

Table a has 74289 records table b has 200k records
My output is 74315 ... where do I put where statement after on replaces 1st and. ?
Solution
‎03-02-2017 01:09 AM
Super User
Super User
Posts: 6,499

Re: Why left join doesn't bring everything from left

You are getting MORE records than exist in the source table A, not LESS.

This happens when there are mulitple records in B for some of the key variables. So in this case there are some values of ID and DATE that have more than one record in table B and also appear in table A.

PROC Star
Posts: 7,363

Re: Why left join doesn't bring everything from left

First you were saying that you weren't getting enough records .. now you're showing too many.

 

Like others have said, post your code and some example data, and an example data file of what you expect.

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 65

Re: Why left join doesn't bring everything from left

Hi Tom your right I just noticed dup with same date and I'd from table a. That's ok what a relief .... follow up in where statement and grouping where do I add where after 1st and ?
Contributor
Posts: 65

Re: Why left join doesn't bring everything from left

I figured it out art thanks for response I had dups
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 170 views
  • 1 like
  • 4 in conversation