Solved
Contributor
Posts: 38

# Join three table

I have 3 data : tab1, tab2 and tab3 like this :

tab1 :

NAME1    NUMBER1

John      145

Max        200

tab2 :

NAME2    NUMBER2

Johny      1415

Maximus        4200

Vince        765

and tab3 :

NAME3    NUMBER3

Johnatan      145

Bruce        200

How to do a join like this ? :

NAME 1        NUMBER1         NAME2       NUMBER2        NAME3        NUMBER3

John                145                  Johny          1415                 Johnatan      145

Max                  200                Maximus        4200                 Bruce        200

.                         .                    Vince        765                             .               .

Accepted Solutions
Solution
‎05-15-2017 04:16 AM
PROC Star
Posts: 1,842

## Re: Join three table

data want;

merge tab1 tab2 tab3;

run;

Regards,

Naveen Srinivasan

All Replies
Solution
‎05-15-2017 04:16 AM
PROC Star
Posts: 1,842

## Re: Join three table

data want;

merge tab1 tab2 tab3;

run;

Regards,

Naveen Srinivasan

PROC Star
Posts: 1,283

## Re: Join three table

It can be done like below.

But why do you want your data like this? Does not seem logical?

``````data tab1;
input NAME1 \$ NUMBER1;
datalines;
John 145
Max 200
;

data tab2;
input NAME2 \$ NUMBER2;
datalines;
Johny 1415
Maximus 4200
Vince 765
;

data tab3;
input NAME3 \$ NUMBER3;
datalines;
Johnatan 145
Bruce 200
;

data want;
merge tab1-tab3;
run;``````
Contributor
Posts: 38

## Re: Join three table

It's because I have more than 500 obersations in each data (tab1, tab2, tab3)

Super User
Posts: 10,280

## Re: Join three table

Yeah, but why the wide structure that only makes your work more tedious in the future?

I'd much prefer

``````data want;
set
tab1 (rename=(name1=name number1=number))
tab2 (rename=(name2=name number2=number))
tab3 (rename=(name3=name number3=number))
;
run;``````

To get a unified table.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.