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;

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