merging multiple rows into 1

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

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

Posted in reply to purveshrana

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.

View solution in original post


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

Re: merging multiple rows into 1

Posted in reply to purveshrana

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

Posted in reply to purveshrana

I figured out a way. Thank you.

Super User
Posts: 23,776

Re: merging multiple rows into 1

Posted in reply to purveshrana

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

 

☑ This topic is solved.

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

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