DATA Step, Macro, Functions and more

per year calculation

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

per year calculation

 

Thanks guys for solving https://communities.sas.com/t5/Base-SAS-Programming/Start-Period-and-End-Period-Calculation/m-p/2868...

refered from this question.

 

how can i limit the calulation to just a year

ie i want to find out average of Cust_Left for that year only for each month.

Output I want is <Avg_Left >

for 11-Apr 22

for 11-May > avg(apr+may)

for 11-Dec > avg(apr+ may+ .. + dec)

for 12-Jan > avg(jan)

for 12-Feb > avg(jan+feb)

 

MonthProjectStart_PeriodNew_CustCust_LeftAvg_LeftEnd_Period
11-Apra01312222109
11-Maya109708553.594
11-Junb9455705979
11-Jula7979636095
11-Auga951549667.2153
11-Sepb1531859071248
11-Octaa24818110375.571326
11-Nova32616111480.375373
11-Decs3732319782.2227
12-Janaaaa5071838686604
Feb-12aa604862455666
Mar-12a666242043.333 
Apr-12s670201837672
May-12a672184739643
Jun-12b643477444.833 
Jul-12a616744945.428 

 

How should i approach this problem any suggestion?

thanks a ton in advance :-)


Accepted Solutions
Solution
‎09-09-2016 01:06 PM
Super Contributor
Posts: 266

Re: per year calculation

Data want (drop = sum_left cnt);

Retain sum_left cnt;

Set have;

If month =1 then do;

 sum_left =0; cnt=0;

End;

sum_left + cust_left;

Cnt+1;

Avg_left= sum_left/cnt;

Run;

 

You need to take care of extracting month value from date colum

 

View solution in original post


All Replies
Solution
‎09-09-2016 01:06 PM
Super Contributor
Posts: 266

Re: per year calculation

Data want (drop = sum_left cnt);

Retain sum_left cnt;

Set have;

If month =1 then do;

 sum_left =0; cnt=0;

End;

sum_left + cust_left;

Cnt+1;

Avg_left= sum_left/cnt;

Run;

 

You need to take care of extracting month value from date colum

 

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 225 views
  • 1 like
  • 2 in conversation