BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cmemtsa
Quartz | Level 8

Hi to all!

I have to find sums in one table but based on different Grouping be each time (relevant Partition by in SQL). How can I do it?

In this code I want to find Sum(Exp) group by P, sum(Exp) group by P, L and sum(MV) group by P, Cd). How many inner joins I need?

proc sql;
select * 

from 
(((select P, L, Exp, MV, sum(Exp) as TotalExpPL,  from t group by P, L) t2
inner join 
(select P, sum(Exp) as TotalExpP from t group by P) t1
on t1.P=t2.P)
((select  P, Cd, sum(MV) as TotalMVPCD from t group by P, Cd) t3
inner join on t1.P=t3.P))
;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @cmemtsa 

Why not using a PROC MEANS instead?

You can then filter on the _type_ variable to get the desired results.

 

proc means data=t noprint;
	class p L Cd;
	var Exp MV;
	output out=want sum=/autoname;
run;

 

View solution in original post

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @cmemtsa 

Why not using a PROC MEANS instead?

You can then filter on the _type_ variable to get the desired results.

 

proc means data=t noprint;
	class p L Cd;
	var Exp MV;
	output out=want sum=/autoname;
run;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 411 views
  • 3 likes
  • 2 in conversation