DATA Step, Macro, Functions and more

Calculate historic date & store in macro variable

Reply
Contributor
Posts: 33

Calculate historic date & store in macro variable

[ Edited ]

Hi,

 

I want to create a macro variable for last year and the month should be July(current month + 3) .

For example : it should be display as 01JUL2015

 

I have tried the below.

data _null_;

call symput('previous_year',put(intnx('month',today(),),intnx('year',today(), -1, 'S'),0,'B'),date9.));

run;

%put &previous_year ;

01APR2015

 

Please let me know.

 

Thanks

 

Super User
Posts: 5,516

Re: Macro

It looks like you're making this a little too complicated.  How about:

 

call symput('previous_year', put(intnx('month', today(), -9), date9.));

 

Last year + 3 months is the same as going back 9 months.

Contributor
Posts: 33

Re: Macro

Posted in reply to Astounding

Thanks !

 

But it should be automated for every month .If it runs for next month then it should be August.

 

Super User
Posts: 5,516

Re: Macro

Not a problem.  Your code already contains the today() function and the intnx function.  You might have to read the documentation to understand what they do.

Super User
Posts: 5,437

Re: Macro

October through December &last_year will actually contain a value of current year...
Data never sleeps
Super User
Super User
Posts: 7,988

Re: Macro

What is the point in putting a date in a macro variable?  You know the formula you want to use, so why not just use that in your code where you need to rather than setting up a text string (which is what a macro variable is), and then messing around with trying to use that as a date.

 

Super User
Posts: 5,437

Re: Macro

Well, one reason could be to use it in a where clause on an indexed variable. Function calls may prevent the index from being used.

Data never sleeps
Super User
Posts: 5,437

Re: Macro

Renamed the topic to better descibe the issue.

Data never sleeps
Ask a Question
Discussion stats
  • 7 replies
  • 351 views
  • 2 likes
  • 4 in conversation