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

How do I put 3 variables from 3 different data together by id?

 

I have 3 different data with common id number but different variables.

 

Data1
id variable1
1 a
2 b
2 s
3 c

Data2
id variable2
1 d
1 e
2 f
3 g
3 h

Data3
id variable3
1 I
1 j
1 k
2 l
2 m
2 n
2 o
3 p
3 q
3 r

All I want is just putting these variables together by id in one dataset:


Desired Dataset
id variable1 variable2 variable3
1 a  d  I
1 .   e  j
1 .   .   k
2 b  f   l
2 s  .   m
2 .   .   n
2 .   .   o
3 c  g  p
3 .   h  q
3 .   .   r

 

 

How could I do that ?  neither merge nor inner join works this way.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

With a small change, you can get MERGE to do this.  Assuming your data sets are sorted:

 

data want;
merge data1 data2 data3;
by id;
output;
call missing(variable1, variable2, variable3);
run;

 

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

With a small change, you can get MERGE to do this.  Assuming your data sets are sorted:

 

data want;
merge data1 data2 data3;
by id;
output;
call missing(variable1, variable2, variable3);
run;

 

 

perilipin
Calcite | Level 5

Wow it works.

Thank you very much!

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1079 views
  • 0 likes
  • 2 in conversation