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

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.

 

--

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Can you show us some sample data?

 

Sounds like PROC TIMESERIES might be a better choice.

mkeintz
PROC Star

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.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
maximas
Calcite | Level 5

Thanks Mkeintz, i tried it in the similar way. 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1334 views
  • 2 likes
  • 3 in conversation