Desktop productivity for business analysts and programmers

combine values in rows based on conditions

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

combine values in rows based on conditions

[ Edited ]

Hi, I need to combine the value of 2 rows based on one variable duplicate "416"

 

numberflagACQflagRETflagBCBSUM_of_SUM_of_ACTV_AMT
41600113.20
41601015.00

 

so the output is like 

 

numberflagACQflagRETflagBCBSUM_of_SUM_of_ACTV_AMT
41601128.20

Accepted Solutions
Solution
‎08-12-2016 05:46 PM
Trusted Advisor
Posts: 1,228

Re: combine values in rows based on conditions

Hi,

 

Please try this:

 

proc sql;
create table want as
select number,sum(flagACQ) as flagACQ,sum(flagRET) as flagRET,sum(flagBCB) as flagBCB,
sum(SUM_of_SUM_of_ACTV_AMT) as SUM_of_SUM_of_ACTV_AMT from have
group by number;
quit;

View solution in original post


All Replies
Solution
‎08-12-2016 05:46 PM
Trusted Advisor
Posts: 1,228

Re: combine values in rows based on conditions

Hi,

 

Please try this:

 

proc sql;
create table want as
select number,sum(flagACQ) as flagACQ,sum(flagRET) as flagRET,sum(flagBCB) as flagBCB,
sum(SUM_of_SUM_of_ACTV_AMT) as SUM_of_SUM_of_ACTV_AMT from have
group by number;
quit;

Occasional Contributor
Posts: 19

combine values in rows based on conditions

 

Hi, I need to combine the value of 2 rows based on one variable duplicate "416"

 

numberflagACQflagRETflagBCBSUM_of_SUM_of_ACTV_AMT
41600113.20
41601015.00

 

so the output is like 

 

numberflagACQflagRETflagBCBSUM_of_SUM_of_ACTV_AMT
41601128.20

 

Thanks

Trusted Advisor
Posts: 1,228

Re: combine values in rows based on conditions

Sql syntax is doing the same as you described. If you print data set "want" you will have the required output.

 

proc print data=want;

run;

Super User
Posts: 11,105

Re: combine values in rows based on conditions

From your example it is not clear whether you want SUM or MAXIMUM value for the variables flagACQ flagRET and flagBCB.

 

What if your example data looked like?

number flagACQ flagRET flagBCB SUM_of_SUM_of_ACTV_AMT
416 0 0 1 13.20
416 0 1 0

15.00

 416           0                1              0                12.00

 

What would the result  be?

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 307 views
  • 0 likes
  • 3 in conversation