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

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!

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.

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
  • 7 replies
  • 1171 views
  • 2 likes
  • 4 in conversation