## merging multiple rows into 1

Solved
Occasional Contributor
Posts: 5

# merging multiple rows into 1

I have a dataset

columns:    A                B                    C           D

APPLE      BALL              123         .

APPLE       BALL                 .           123

I WANT AN OUTPUT TO BE LIKE FOLLOWING

A                       B                       C            D

APPLE                 BALL               123           123

How can I solve this in single step ? Thanks

Accepted Solutions
Solution
‎09-05-2017 03:09 PM
Super User
Posts: 6,785

## Re: merging multiple rows into 1

If it takes just column A to determine a unique observation:

data want;

update have (obs=0) have;

by a;

run;

If it takes the combination of both columns A and B, switch to:

data want;

update have (obs=0) have;

by a b;

run;

In any case, the data need to be in sorted order to be allowed to use the BY statement.

All Replies
Solution
‎09-05-2017 03:09 PM
Super User
Posts: 6,785

## Re: merging multiple rows into 1

If it takes just column A to determine a unique observation:

data want;

update have (obs=0) have;

by a;

run;

If it takes the combination of both columns A and B, switch to:

data want;

update have (obs=0) have;

by a b;

run;

In any case, the data need to be in sorted order to be allowed to use the BY statement.

Occasional Contributor
Posts: 5

## Re: merging multiple rows into 1

I figured out a way. Thank you.

Super User
Posts: 23,776

## Re: merging multiple rows into 1

@purveshrana for completion, please post the solution or mark one here as correct.

☑ This topic is solved.

Discussion stats
• 3 replies
• 104 views
• 2 likes
• 3 in conversation