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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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