# how to combine rows of paired data into one row

#### statsguy20

##### New Member
Hi,
I have data that is structured like the following:
location team score
away ny 100
home la 80
away chi 95
home det 85

But I would like to transform the pairs of data to be structured like this:
away_team home_team away_score home_score
ny la 100 80
chi det 95 85

Does anyone know how to do this? Thanks!

#### chetan.apa

##### Member
Probably, you could do this easily in a data step..something like this
I have assumed that the data rows to be paired are in consecutive lines. Note that I have not tested this code.

Code:
data abc(keep=away_team home_team away_score home_score);
set abc;
retain away_team home_team away_score home_score;
if location="home" then do;
home_team=team;
home_score=score;
end;
else do;
away_team=team;
away_score=score;
end;
if mod(_n_,2)=0 then output;
run;

#### statsguy20

##### New Member
amazing, thank you! what operation is the retain statement performing in the code you wrote?