BookmarkSubscribeRSS Feed
Corinthian94
Obsidian | Level 7

Hi all,

 

I'm having some issues with the below code and datasets. I am trying to use a proc sql left join to bring the two datasets together with a new variable, but when I do it adds an extra two from the second dataset instead of only joining to the two already existing in the first dataset. Code and pictures of the three datasets in order below. Thank you in advance for the help!

 

proc sql; create table eligs as select
a. * ,
b. x_dupIPelig label = "Match with other Elig" as eligIP_flag

from eligIP2 a left join eligIPdups b
on a.screener_ID = b.screener_ID;
quit;

 

eligIP2:

Corinthian94_0-1692720733110.png

Eligipdups:

Corinthian94_1-1692720785621.png

 

Eligs(Created dataset):

Corinthian94_2-1692720841076.png

 

 

 

1 REPLY 1
ballardw
Super User

That is the basic behavior of a left join: ALL of the records in the "left" set are joined to ALL of the records that match in the "right" set.

 

Perhaps you need to join on two or more variables such as

proc sql; 
   create table eligs as 
   select  a. * ,
   b. x_dupIPelig label = "Match with other Elig" as eligIP_flag

   from eligIP2 a 
            left join 
            eligIPdups b
    on a.screener_ID = b.screener_ID
        and a.vidnum=b.vidnum
   ;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 576 views
  • 0 likes
  • 2 in conversation