Desktop productivity for business analysts and programmers

Using INTNX function

Posts: 0

Using INTNX function

I am trying to increment a date by one day so it is the beginning of a month and have it appear in a report title. Once I have the answer, the date will be a variable selected by the user that is actually an end-of-month date.

%let x=intnx('DAY', '31Mar08'd,1);
%put x / x date9.;

TITLE1 "Date = &x";

Here's the results in the report:

Date = intnx('DAY', '31Mar08'd,1)

I would like it to show Date = 04/01/2008.

Any ideas??
Super Contributor
Posts: 309

Re: Using INTNX function

The problem is that you are mixing macro-code and normal sas-code. In this case the intnx-function will never be executed. Some functions can be used in macro-statements via the %sysfunc-macro-function.

The following code uses a data-step to create the macro-variable firstDay.

data _null_;
firstDay = put(intnx("DAY", "31Mar08"d, 1), mmddyy8.);
call symput("firstDay", firstDay);

TITLE1 "Date = &firstDay";

proc print data=sashelp.class;
[/pre] Thinking before the first coffee is not always a good idea ;-) I removed the wrong idea about intnx and sysfunc.

Message was edited by: andreas_lds
Super User
Posts: 5,380

Re: Using INTNX function

If you know that your base date is the last date of the previous month, just add 1:

date = input_date + 1;

Otherwise, you could try:

date = intnx('MONTH',input_date,1,'BEGINNING');

Data never sleeps
Posts: 0

Re: Using INTNX function

%SYSFUNC supports the intnx functions

%let x=%sysfunc(intnx(day,"31Mar2008"d,1,B),ddmmyy8.);
%put &x;


Hope this could be handy.
Posts: 0

Re: Using INTNX function

Thank you. This worked when I "hard code" the date that I need to increment. I'm having trouble now when I want to use a parameter value that the user selected.

%let beg_date = &Prior_Month_End;
TITLE1 "&beg_date";

Result: '31Mar2008:0:0:0'dt

When I try to put Prior_Month_End in the sysfunc
%let beg_date = %sysfunc(intnx(day,&prior_month_end,1,beginning));
Result: . (period)

w/out the '&' on Prior_Month_End, I get an error message.

When I try it a different way, it appears the "value" for Prior_Month_End "starts at 1/1/1960.
%let beg_date = %sysfunc(intnx(day,%sysfunc(Datepart(&Prior_Month_End),
Result: 01/02/1960

Any more help would be appreciated.
Super User
Posts: 5,380

Re: Using INTNX function

Sorry, I don't get the full picture here.
Does &Prior_Month_End has datetime value?
Is this only used for your title statement?

If it's only for displaying a %substr would do:

TITLE1 "%substr(&beg_date,2,9)";

If you want to use for some subset, I guess you need to get the datepart out of it, here you can use %substr as well (as long as you are sure of the format of the value):

%let beg_date = "%substr(&Prior_Month_End,2,7)"d;

Or nicer, working with a SAS date function:

%let beg_date = %sysfunc(datepart(&a));

Hope this helps,
Data never sleeps
Ask a Question
Discussion stats
  • 5 replies
  • 3 in conversation