Solved
New Contributor
Posts: 4

# how can I create a total based on two group variables

Dear All,

I need to obtain a total based to two group variables(Subgrp_Total shown in the below table).

IdSub_GroupAmtSubgrp_Total
AAZ12030

AA

Z11030
ABZ22050
ABZ21050
ABZ22050
ACZ34545

I have tried calculating the cumulative total for the group by using the Id and Sub_group as the two by variable and the total obtained in the last observation of the sub group, but I need to assign the total for a sub group to each observation. Also is there a alternate way by using sas procedures.

Thanks in advance for the help!

Accepted Solutions
Solution
‎11-17-2014 10:39 AM
Posts: 1,270

## Re: how can I create a total based on two group variables

proc sql;

create table want as

select *,sum(amt) as Subgrp_Total from have

group by id,sub_group;

quit;

All Replies
Solution
‎11-17-2014 10:39 AM
Posts: 1,270

## Re: how can I create a total based on two group variables

proc sql;

create table want as

select *,sum(amt) as Subgrp_Total from have

group by id,sub_group;

quit;

🔒 This topic is solved and locked.