BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kajal_30
Quartz | Level 8

Hi all,

 

I have 4 datasets as below and requirement for the table want are :

- Ignore col1 values which are not common for all 4 tables

- join all col1 col2 col3 col4 values in the want table to show all different values for col2 in each table.

 

Table 1
col1col2
1yes
2yes
3yes
4yes
5 

 

Table 2 
col1col2
1yes
2no1
3yes
4no1

 

Table 3
col1col2
1yes
2no2
3yes
4no2

 

Table 4
col1col2
1yes
2no3
3yes
4no3

 

table want
col1col2col3col4col5
1yesyesyesyes
2yesno1no2no3
3yesyesyesyes
4yesno1no2no3

 

Thanks in advance

kajal

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
  merge T1(in=IN1)
        T2(in=IN2 rename=(COL2=COL3)) 
        T3(in=IN3 rename=(COL2=COL4))
        T4(in=IN4 rename=(COL2=COL5));
  by COL1;      
  if IN1 & IN2 & IN3 & IN4;
run;

 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
  merge T1(in=IN1)
        T2(in=IN2 rename=(COL2=COL3)) 
        T3(in=IN3 rename=(COL2=COL4))
        T4(in=IN4 rename=(COL2=COL5));
  by COL1;      
  if IN1 & IN2 & IN3 & IN4;
run;

 

kajal_30
Quartz | Level 8
Thank you
Kurt_Bremser
Super User

Just for giggles:

proc sql;
create table want as
  select
    t1.col1,
    t1.col2,
    t2.col2 as col3,
    t3.col2 as col4,
    t4.col2 as col5
  from table1 t1, table2 t2, table3 t3, table4 t4
  where
    t1.col1 = t2.col1 and
    t1.col1 = t3.col1 and
    t1.col1 = t4.col1
;
quit;
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
  • 4 replies
  • 1089 views
  • 0 likes
  • 3 in conversation