DATA Step, Macro, Functions and more

Summation

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Summation

I want to collapse dollars by summing by a specific variable.  Every column in these two observations is the exact same except the PYMT_AMT_DLR.  I would like to get that load to add up together then i can can sum by TRIP later and eventually do a comparison. 

 

LD_LEG_IDTRIP_IDPYMNT_AMT_DLR
10790980349314144.00
10790981349314-24.04
10790981349314144.00

 

Any help would be appreciated!


Accepted Solutions
Solution
‎07-25-2016 11:55 PM
Respected Advisor
Posts: 4,930

Re: Summation

proc SQL is most flexible for this kind of task:

 

proc sql;
create table by_Ld_Leg as
select 
	TRIP_ID, 
	LD_LEG_ID,
	sum(PYMNT_AMT_DLR) as sum_by_leg
from myData
group by TRIP_ID, LD_LEG_ID;
/* Later ... */
create table byTrip as
select
	TRIP_ID,
	sum(sum_by_leg) as sum_by_trip
from by_Ld_Leg
group by TRIP_ID;
quit;
PG

View solution in original post


All Replies
Super User
Posts: 5,434

Re: Summation

Not sure what you want, a straight summary?
Can be done in tons of ways : SQL, PROC SUMMARY, even the data step...
Data never sleeps
Solution
‎07-25-2016 11:55 PM
Respected Advisor
Posts: 4,930

Re: Summation

proc SQL is most flexible for this kind of task:

 

proc sql;
create table by_Ld_Leg as
select 
	TRIP_ID, 
	LD_LEG_ID,
	sum(PYMNT_AMT_DLR) as sum_by_leg
from myData
group by TRIP_ID, LD_LEG_ID;
/* Later ... */
create table byTrip as
select
	TRIP_ID,
	sum(sum_by_leg) as sum_by_trip
from by_Ld_Leg
group by TRIP_ID;
quit;
PG
Occasional Contributor
Posts: 16

Re: Summation

This worked exactly the way that I wanted, thank you!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 246 views
  • 0 likes
  • 3 in conversation