Learning SAS? Welcome to the exclusive online community for all SAS learners.

how can I create a total based on two group variables

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

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
ADZ22550
ADZ21550
ADZ21050

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
Trusted Advisor
Posts: 1,228

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;

View solution in original post


All Replies
Solution
‎11-17-2014 10:39 AM
Trusted Advisor
Posts: 1,228

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.

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

Discussion stats
  • 1 reply
  • 238 views
  • 0 likes
  • 2 in conversation