## Combine (Interleave) two columns, keeping all other columns, too

Solved
Regular Contributor
Posts: 238

# Combine (Interleave) two columns, keeping all other columns, too

Please see the following data set:

``````Bob Paul 120
Scott Joe 100
Betty Trish 97
``````

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

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

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

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

How can this be done efficiently?

Any help greatly appreciated.

Thanks!

Nicholas Kormanik

Accepted Solutions
Solution
‎07-03-2016 05:46 AM
Posts: 5,526

## Re: Combine (Interleave) two columns, keeping all other columns, too

Another way:

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

All Replies
Posts: 1,270

## Re: Combine (Interleave) two columns, keeping all other columns, too

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;

Solution
‎07-03-2016 05:46 AM
Posts: 5,526

## Re: Combine (Interleave) two columns, keeping all other columns, too

Another way:

``````data want;
set have;
do name = name1, name2;
output;
end;
drop name1 name2;
run;``````
PG
Super User
Posts: 23,711

## Re: Combine (Interleave) two columns, keeping all other columns, too

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.

☑ This topic is solved.