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

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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