BookmarkSubscribeRSS Feed
AndreasF
Fluorite | Level 6

Hey Community,

 

I would like to use create to macro variables with an enddate and startdate in the format 20170817 for Aug, 17, 2017. The "initial" variable report_date is in the format 17.08.2017.

 

This is the code I use:

 

/* Variables */
%let report_date = 17.08.2017;
%let EndDate = %sysfunc(inputn(&report_date,ddmmyy10.),yymmddn8.);
%let StartDate = %sysfunc(intnx(month,&EndDate,-12,b),yymmddn8.);
%put &StartDate;

However, I get this warning:

WARNING: An argument to the function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.

 

OK. Does not work. I think the format 2017-08-17 would also be ok. So I change the code to:

/* Variables */
%let report_date = 17.08.2017;
%let EndDate = %sysfunc(inputn(&report_date,ddmmyy10.),yymmdd10.);
%let StartDate = %sysfunc(intnx(month,&EndDate,-12,b),yymmdd10.);
%put &StartDate;

Ok. It runs without a warning. Here is the output:

1964-06-01

 

Can anyone help me with that? Ideally with Plan A.

 

Thanks,

Andreas

 

2 REPLIES 2
Quentin
Super User

Hi,

 

Looks like your calculation of &EndDate is doing what you want:

 

20   %let report_date = 17.08.2017;
21   %let EndDate = %sysfunc(inputn(&report_date,ddmmyy10.),yymmddn8.);
22   %put &=EndDate;
ENDDATE=20170817

 

When you compute the StartDate via INTNX(), INTNX() needs a date value to use as a base for the calculation.  You gave it EndDate, which has a value of 20170817 which you know means August 17, 2017, but in SAS that number represents a date that is twenty million days after Jan 1, 1960.  Apparently that date is too far into the future to be valid for INTNX.

 

So the answer is to convert your value 20170817 back into the SAS date for August 17, 2017, which you can do by using the inputn() function again:

 

23   %let StartDate = %sysfunc(intnx(month,%sysfunc(inputn(&EndDate,yymmdd8.)),-12,b),yymmddn8.);
24   %put &=StartDate;
STARTDATE=20160801
The Boston Area SAS Users Group is hosting free webinars!
Next up: Bart Jablonski and I present 53 (+3) ways to do a table lookup on Wednesday Sep 18.
Register now at https://www.basug.org/events.
Ksharp
Super User
%let report_date = 17.08.2017;
%let EndDate = %sysfunc(inputn(&report_date,ddmmyy10.),yymmddn8.);

%let _EndDate = %sysfunc(inputn(&report_date,ddmmyy10.));
%let StartDate = %sysfunc(intnx(month,&_EndDate,-12,b),yymmddn8.);
%put &StartDate;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1458 views
  • 1 like
  • 3 in conversation