DATA Step, Macro, Functions and more

Date Macro Financial Year

Reply
Contributor
Posts: 42

Date Macro Financial Year

Hi,

Any idea how to create a date macro for the financial year please?

Currently we key in the dates as below

%let fin_start = 01APR2017;
%let fin_end = 01APR2018;

Thanks
PROC Star
Posts: 1,190

Re: Date Macro Financial Year

Posted in reply to Brandon16

What exactly do you want to do?

 

See this thread for inspiration

 

https://communities.sas.com/t5/SAS-Visual-Analytics/I-would-like-to-know-how-to-make-fiscal-year/td-...

Contributor
Posts: 42

Re: Date Macro Financial Year

Posted in reply to Brandon16
I want to take out the manual element of it so we are never required to update it, even when the financial year changes.
PROC Star
Posts: 1,190

Re: Date Macro Financial Year

Posted in reply to Brandon16

Something like this?

 

data _null_;
   call symputx('fin_start', mdy(4, 1, year(today())));
   call symputx('fin_end', mdy(4, 1, year(today())+1));
run;

%put &fin_start. &fin_end.;
Super User
Posts: 13,046

Re: Date Macro Financial Year

Posted in reply to Brandon16

How do you use that information? If the main purpose is to determine if a date value is in a given fiscal year you might get by with either a custom function or something similar to:

 

%macro myfiscalyear(date);
/* date must be a sas date value either 
  in the 'ddmmyyyy'd form or SAS numeric value of a date*/
%eval (%sysfunc(year(&date)) + %eval(%sysfunc(month(&date))> 4 ))
%mend;

%put Fiscal year of 23AUG2018 is %myfiscalyear('23AUG2018'd);


%put Fiscal year of 12345 is %myfiscalyear(12345);
Super User
Posts: 10,615

Re: Date Macro Financial Year

Posted in reply to Brandon16
%let fin_start = %sysfunc(intnx(year.4,%sysfunc(today()),0,b),date9.);
%let fin_end =  %sysfunc(intnx(year,"&fin_start"d,1,s),date9.);

%put &fin_start  &fin_end ;
Ask a Question
Discussion stats
  • 5 replies
  • 115 views
  • 0 likes
  • 4 in conversation