## combine values in rows based on conditions

Solved
Occasional Contributor
Posts: 19

# combine values in rows based on conditions

[ Edited ]

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

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

so the output is like

 number flagACQ flagRET flagBCB SUM_of_SUM_of_ACTV_AMT 416 0 1 1 28.20

Accepted Solutions
Solution
‎08-12-2016 05:46 PM
Posts: 1,270

## Re: combine values in rows based on conditions

Hi,

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;

All Replies
Solution
‎08-12-2016 05:46 PM
Posts: 1,270

## Re: combine values in rows based on conditions

Hi,

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"

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

so the output is like

 number flagACQ flagRET flagBCB SUM_of_SUM_of_ACTV_AMT 416 0 1 1 28.20

Thanks

Posts: 1,270

## 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: 13,941

## 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.