Help using Base SAS procedures

Cummulative counter with reset at certain point

Reply
Occasional Contributor
Posts: 7

Cummulative counter with reset at certain point

Suppose I have data in the following format:

Year Month Total

2009 4 16

2009 5 18

2009 6 12

2009 7 15

2009 8 11

2009 9 12

2009 10 7

2009 11 6

2009 12 9

2010 1 7

2010 2 8

2010 3 92

2010 4 3

2010 5 3

2010 6 3

2010 7 3

2010 8 5

2010 9 3

2010 10 08

2010 11 0

2010 12 2

2011 1 6

2011 2 5

2011 3 9

2011 4 17

2011 5 9

I am trying to obtain cumulative total of these observation (this alone would not be difficult), however I want the cumulative counter to 'reset' at the beginning of financial year (i.e. get cumulatives for 04/2009 - 03/2010, 04/2010 - 03/2011 etc.). Could anyone suggest appropriate code?

Thank you,

Simi

Respected Advisor
Posts: 3,777

Cummulative counter with reset at certain point

INTNX with shift.

data test;

   input Year Month Total;

   date = mdy(month,1,year);

   fyear = intnx('year.4',date,0);

   format date fyear date9.;

   cards;

2009 4 16

2009 5 18

2009 6 12

2009 7 15

2009 8 11

2009 9 12

2009 10 7

2009 11 6

2009 12 9

2010 1 7

2010 2 8

2010 3 92

2010 4 3

2010 5 3

2010 6 3

2010 7 3

2010 8 5

2010 9 3

2010 10 08

2010 11 0

2010 12 2

2011 1 6

2011 2 5

2011 3 9

2011 4 17

2011 5 9

;;;;

   run;

proc print;

   run;

proc freq;

   weight total;

   tables fyear;

   format fyear year.;

   run;

Occasional Contributor
Posts: 7

Cummulative counter with reset at certain point

Thanks a lot, will definitelly remember INTNX now...

Ask a Question
Discussion stats
  • 2 replies
  • 124 views
  • 0 likes
  • 2 in conversation