Help using Base SAS procedures

many to many merge using proc sql or datasteps?

Accepted Solution Solved
Reply
Super Contributor
Posts: 301
Accepted Solution

many to many merge using proc sql or datasteps?

Hi all,'ve got the next dataset (have):

data have;

length subjid 8 color1 color2 $20;

input subjid $ color1 $ color2;

datalines;

1 blue       blue

2 red       grey 

3 yellow   blue

4 green     green

5 black     yellow

6 white     pink

7 purple    yellow

;

run;

I am interested to create a final dataset (want) like this:

color2    other

blue     blue

grey    

green   green

yellow  yellow

pink  

as you can see I am interested to know which color in (color2) has been assigned to (color1), and which color in (color2) cant be assigned to (color 1) because  are different (blanck values)...in this example would be grey and pink.

Thanks in advance,

V.


Accepted Solutions
Solution
‎04-17-2013 02:16 PM
Respected Advisor
Posts: 3,124

Re: many to many merge using proc sql or datasteps?

How about this:

data have;

input (subjid color1 color2) (:$);

datalines;

1 blue blue

2 red grey 

3 yellow blue

4 green green

5 black yellow

6 white pink

7 purple yellow

;

proc sql;

  select distinct a.color2, b.color1 as other

  from have a

  left join

have b

on a.color2=b.color1

;

quit;

Haikuo

View solution in original post


All Replies
Super Contributor
Posts: 301

Re: many to many merge using proc sql or datasteps?

maybe using arrays...please some help.

Thanks.

Solution
‎04-17-2013 02:16 PM
Respected Advisor
Posts: 3,124

Re: many to many merge using proc sql or datasteps?

How about this:

data have;

input (subjid color1 color2) (:$);

datalines;

1 blue blue

2 red grey 

3 yellow blue

4 green green

5 black yellow

6 white pink

7 purple yellow

;

proc sql;

  select distinct a.color2, b.color1 as other

  from have a

  left join

have b

on a.color2=b.color1

;

quit;

Haikuo

Super Contributor
Posts: 301

Re: many to many merge using proc sql or datasteps?

Brilliant Hai.Kuo

Many thanks.

Cheers,

V.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 175 views
  • 0 likes
  • 2 in conversation