DATA Step, Macro, Functions and more

Combine multiple rows to a single row

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

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.

 

ABCDE
28846512....
.10942982...
..1418164..
...207.29.
....20092412

 

I want the above table to look like below:

 

ABCDE
28846512109429821418164207.2920092412

 

Value your help.

 

Kind regards,

Mags


Accepted Solutions
Solution
‎04-30-2018 01:40 AM
Esteemed Advisor
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

View solution in original post


All Replies
Trusted Advisor
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 ?

 

The solution depends on your answers.

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 .
Trusted Advisor
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
Esteemed Advisor
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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 361 views
  • 1 like
  • 4 in conversation