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

I have

 

A:

 

Name score1

a1 80

a2 70

a3 60

 

B: name score2

a1 70

a3 60

a4 50

 

What I want to get is:

 

name score1 score2

a1 80 70

a2 70 .

a3 60 60

a4 . 50

 

but if I use full join

what I get is:

name score1 score2

a1 80 70

a2 70 .

a3 60 60

. . 50

 

how to solve this issue?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Please post your code.

 

You will need to use the COALESCE function for the name column from both tables.

 

Given your data as posted, a DATA step is much better:

data want;
merge a b;
by name;
run;

 


@walterwang wrote:

I have

 

A:

 

Name score1

a1 80

a2 70

a3 60

 

B: name score2

a1 70

a3 60

a4 50

 

What I want to get is:

 

name score1 score2

a1 80 70

a2 70 .

a3 60 60

a4 . 50

 

but if I use full join

what I get is:

name score1 score2

a1 80 70

a2 70 .

a3 60 60

. . 50

 

how to solve this issue?

 

 


 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Please post your code.

 

You will need to use the COALESCE function for the name column from both tables.

 

Given your data as posted, a DATA step is much better:

data want;
merge a b;
by name;
run;

 


@walterwang wrote:

I have

 

A:

 

Name score1

a1 80

a2 70

a3 60

 

B: name score2

a1 70

a3 60

a4 50

 

What I want to get is:

 

name score1 score2

a1 80 70

a2 70 .

a3 60 60

a4 . 50

 

but if I use full join

what I get is:

name score1 score2

a1 80 70

a2 70 .

a3 60 60

. . 50

 

how to solve this issue?

 

 


 

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
  • 473 views
  • 0 likes
  • 2 in conversation