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

 

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 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11

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

1 REPLY 1
RahulG
Barite | Level 11

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

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1176 views
  • 1 like
  • 2 in conversation