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;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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