Help using Base SAS procedures

Financial Year calculations (FYTD) - Proc expand

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Financial Year calculations (FYTD) - Proc expand

Hi, 

 

I have monthly sales data for  33 markets for 5 years, I want to calculate FYTD sales.

For us the Financial Year starts from month of April and ends in March.

e.g. FYTD for October 2017 will be sum of sales from April 17 to Oct 17.

 

So I have to create a variable named as FYTD and corresponding to each month it will have FYTD sales.

 

Can i try it using proc expand.

 

--


Accepted Solutions
Solution
‎10-09-2017 12:07 PM
Trusted Advisor
Posts: 1,345

Re: Financial Year calculations (FYTD) - Proc expand

Here's an example using the monthly data series sashelp.stocks, which I sort because it is stored in reverse chronological order.

 

 

proc sort data=sashelp.stocks  (keep=stock date volume) out=have;
  by stock date;
run;

data want;
  set have;
  by stock;
  Fytd_vol+volume;   format fytd_vol comma13.0;
  if intck('year.4',lag(date),date) then fytd_vol=volume;
  else if first.stock then fytd_vol=volume;
run;

 

  1. The FYTD_VOL + volume is a "sum" statement which increments fytd_vol without the normal reset to missing at the top of  the data step.
  2. The "year.4" time unit is  a way to determine years that begin in April, rather than Jan, which provides a way to detect start of fiscal year, by seeing if a March/April boundary is crossed between preceding date and current date.

View solution in original post


All Replies
PROC Star
Posts: 1,283

Re: Financial Year calculations (FYTD) - Proc expand

[ Edited ]

Can you show us some sample data?

 

Sounds like PROC TIMESERIES might be a better choice.

Solution
‎10-09-2017 12:07 PM
Trusted Advisor
Posts: 1,345

Re: Financial Year calculations (FYTD) - Proc expand

Here's an example using the monthly data series sashelp.stocks, which I sort because it is stored in reverse chronological order.

 

 

proc sort data=sashelp.stocks  (keep=stock date volume) out=have;
  by stock date;
run;

data want;
  set have;
  by stock;
  Fytd_vol+volume;   format fytd_vol comma13.0;
  if intck('year.4',lag(date),date) then fytd_vol=volume;
  else if first.stock then fytd_vol=volume;
run;

 

  1. The FYTD_VOL + volume is a "sum" statement which increments fytd_vol without the normal reset to missing at the top of  the data step.
  2. The "year.4" time unit is  a way to determine years that begin in April, rather than Jan, which provides a way to detect start of fiscal year, by seeing if a March/April boundary is crossed between preceding date and current date.
New Contributor
Posts: 2

Re: Financial Year calculations (FYTD) - Proc expand

Thanks Mkeintz, i tried it in the similar way. Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 218 views
  • 2 likes
  • 3 in conversation