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

Please see the following data set:

 

Bob Paul 120
Tina Adele 111
Scott Joe 100
Betty Trish 97
Mark Adam 95

 

Three columns: Name#1, Name#2, Score.

 

I would like to join the columns to produce the following:

 

Bob 120
Paul 120
Tina 111
Adele 111
Scott 100
Joe 100
Betty 97
Trish 97
Mark 95
Adam 95

Two columns: Name#1 OR Name#2, Score

 

How can this be done efficiently?

 

Any help greatly appreciated.

 

Thanks!

 

Nicholas Kormanik

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Another way:

 

data want;
set have;
do name = name1, name2;
    output;
    end;
drop name1 name2;
run;
PG

View solution in original post

3 REPLIES 3
stat_sas
Ammonite | Level 13

Hi,

 

One way to do this:

 

data want(keep=Name score);
set have;
array n(*) name1 name2;
do i=1 to dim(n);
Name=n(i);
output;
end;
run;

 

 

PGStats
Opal | Level 21

Another way:

 

data want;
set have;
do name = name1, name2;
    output;
    end;
drop name1 name2;
run;
PG
Reeza
Super User

Data want;

set have (rename=name1=name keep=(name score))

     Have (rename=name2=name keep=(name score));

run;

 

You may need to play with the keep statement. I never remember if you reference a renamed variable with the original or new name in the keep section. 

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
  • 953 views
  • 2 likes
  • 4 in conversation