BookmarkSubscribeRSS Feed
Not applicable
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??
Jade | Level 19
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
Tourmaline | Level 20
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
Not applicable
%SYSFUNC supports the intnx functions

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


Hope this could be handy.
Not applicable
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.
Tourmaline | Level 20
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


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

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
  • 5 replies
  • 3 in conversation