Solved
Contributor
Posts: 30

# Combine multiple rows to a single row

Hello,

I'm hoping someone could help me with the following.

I have the following output table and would like the data to be in one row instead of multiple rows.

 A B C D E 28846512 . . . . . 10942982 . . . . . 1418164 . . . . . 207.29 . . . . . 20092412

I want the above table to look like below:

 A B C D E 28846512 10942982 1418164 207.29 20092412

Kind regards,

Mags

Accepted Solutions
Solution
‎04-30-2018 01:40 AM
Posts: 5,535

## Re: Combine multiple rows to a single row

``````proc means data=have noprint;
var _all_;
output out=want(drop=_: ) max=;
run;``````
PG

All Replies
Posts: 1,837

## Re: Combine multiple rows to a single row

[ Edited ]

What type of input you have ? is it a sas dataset or external file (like: .txt or .xsl) ?

Is there an ID column ? How many variables are in a row ?

What do you want to do with the data ?

Why not save it all in one column ?

Contributor
Posts: 30

## Re: Combine multiple rows to a single row

Hi Shmuel,

It is a sas dataset and does not have a column ID.

Thank you .
Posts: 1,837

## Re: Combine multiple rows to a single row

Assuming there are 5 columns:

``````data want;
set have;
retain v1-v5;
array  vx v1-v5;
array inp a b c d e;
i = mod(_N_, 5);
vx(i) - inp(i);

if i=0 then output;
keep v1-v5;
run;
``````
Contributor
Posts: 30

## Re: Combine multiple rows to a single row

Thanks kindly Shmuel.

Solution
‎04-30-2018 01:40 AM
Posts: 5,535

## Re: Combine multiple rows to a single row

``````proc means data=have noprint;
var _all_;
output out=want(drop=_: ) max=;
run;``````
PG
Contributor
Posts: 30

## Re: Combine multiple rows to a single row

Thank you so much PG. It works perfectly.

New Contributor
Posts: 2

## Re: Combine multiple rows to a single row

Beautiful solution!

☑ This topic is solved.