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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

3 REPLIES 3
michtka
Fluorite | Level 6

maybe using arrays...please some help.

Thanks.

Haikuo
Onyx | Level 15

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

michtka
Fluorite | Level 6

Brilliant Hai.Kuo

Many thanks.

Cheers,

V.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1240 views
  • 0 likes
  • 2 in conversation