BookmarkSubscribeRSS Feed
cho16
Obsidian | Level 7

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

 

7 REPLIES 7
Astounding
PROC Star

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.

cho16
Obsidian | Level 7

Thanks !

 

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

 

Astounding
PROC Star

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.

LinusH
Tourmaline | Level 20
October through December &last_year will actually contain a value of current year...
Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

LinusH
Tourmaline | Level 20

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
LinusH
Tourmaline | Level 20

Renamed the topic to better descibe the issue.

Data never sleeps

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 4169 views
  • 2 likes
  • 4 in conversation